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.