QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 32 MB Total points: 100

#22499. 母牛健身操

Statistics

Farmer John 不断让牛在牧场各条路上锻炼保持健康。道路由顶点和双向边表示,每对顶点间恰有一条简单路径,抽象结构很像树。每条蜿蜒的边竟然等长。

聪明的牛将任意一组道路中任意两顶点的最大距离叫作路径长度。若太大,就完全拒绝锻炼。

FJ 测得 $V$($2 \le V \le 100,000$)个顶点,编号 $1..V$。可阻断两顶点间道路,生成更多组,并减少形成的两组的路径长度。

从完全连通的一组树状道路出发,阻断 $S$($1 \le S \le V-1$)条,得 $S+1$ 组。目标选择最佳阻断,使所有组的最大路径长度最小。

列出树的全部 $V-1$ 条边,端点 $A_{i}$($1 \le A_{i} \le V$)、$B_{i}$($1 \le B_{i} \le V; A_{i} \ne B_{i}$)。

例如如下线状道路树有 7 个顶点:

                   1---2---3---4---5---6---7

可阻断两条时,可能选出:1---2 | 3---4 | 5---6---7

最长路径长度为 $2$,即本例答案,无法更好。

时间限制:2 秒

内存限制:32 MB

输入格式

  • 第 1 行:两个空格分隔整数 $V$、$S$。
  • 第 $2..V$ 行:两个空格分隔整数 $A_{i}$、$B_{i}$。

输出格式

  • 第 1 行:一个整数,表示 $S$ 次阻断能达到的最优最大路径长度。

样例

输入格式 1

7 2
6 7
3 4
6 5
1 2
3 2
4 5

输出格式 1

2

题目作者:Michael Cohen,2010

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.