atcoder#ARC116E. [ARC116E] Spread of Information

[ARC116E] Spread of Information

Score : 800800 points

Problem Statement

Takahashi Kingdom has NN towns, called Town 11 through NN. There are N1N-1 roads in this kingdom. The ii-th road connects Town uiu_i and Town viv_i bidirectionally. For any two towns aa and bb, it is possible to get from Town aa to Town bb by traversing some roads.

Takahashi, the king, wants to spread some information all over the kingdom. Since he is busy, he can directly transmit this information to at most KK towns.

Assume that Takahashi finishes transmitting the information at time 00. Then, for each t=1,2,3,t = 1, 2, 3, \cdots, the following happens:

  • For towns aa and bb directly connected by a road, if aa has already received the information at time t0.5t - 0.5 but bb has not, bb receives it at time tt.

Takahashi wants to choose the KK towns to transmit the information to minimize the time taken until every town receives it. Find the minimum time this takes.

Constraints

  • All values in input are integers.
  • 1K<N2×1051 \leq K < N \leq 2 \times 10^5
  • 1ui,viN1 \leq u_i, v_i \leq N
  • For any two towns aa and bb, it is possible to get from Town aa to Town bb by traversing some roads.

Input

Input is given from Standard Input in the following format:

NN KK

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uN1u_{N-1} vN1v_{N-1}

Output

Print the answer.

5 2
1 2
2 3
3 4
4 5
1

If Takahashi directly transmits the information to Town 22 and 44, Town 1,2,3,4,51, 2, 3, 4, 5 receives it at time 1,0,1,0,11, 0, 1, 0, 1, respectively. In this case, the information is spread all over the kingdom at time 11. We can prove that this is the earliest possible time.

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