QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#478. 地铁

统计

某城市长期以来一直致力于地铁建设。由于财务管理不善且成本估算严重不足,导致没有预留购买列车的资金。结果,虽然建成了许多车站,但只完成了部分规划中的隧道——仅能勉强保证任意两个车站之间存在连通路径。隧道的数量(每条隧道均为双向)比已建成的车站数量少 1。利用剩余的资金,仅购买了少数几列列车。

为了挽回颜面,董事会要求你规划地铁路线,使得能够被覆盖的车站数量最大化。每列列车都在指定的路线上行驶。路线不能分叉(即从同一个车站出发的三条隧道不能属于同一条路线)。不同的路线可以经过同一个车站或隧道。

请编写一个程序:

  • 从标准输入读取隧道系统的描述以及计划规划的地铁线路数量;
  • 计算在指定数量的地铁线路下,能够覆盖的车站的最大数量;
  • 将结果输出到标准输出。

输入格式

第一行包含两个整数 $n$ 和 $l$ ($2 ≤ n ≤ 1\,000\,000$, $0 ≤ l ≤ n$),中间用空格分隔。$n$ 表示车站数量,$l$ 表示计划规划的地铁线路数量。车站编号从 $1$ 到 $n$。

接下来的 $n-1$ 行,每行包含两个不同的整数,中间用空格分隔。第 $i+1$ 行中的数字 $1 ≤ a_i,b_i ≤ n$ 表示第 $i$ 条隧道连接的两个车站。

输出格式

输出的第一行且仅包含一行,为一个整数,表示地铁线路能够覆盖的车站的最大数量。

样例

输入 1

17 3
1 2
3 2
2 4
5 2
5 6
5 8
7 8
9 8
5 10
10 13
13 14
10 12
12 11
15 17
15 16
15 10

输出 1

13

该图展示了隧道系统(其中标记了地铁路线)的一种最优配置。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.