atcoder#ARC116E. [ARC116E] Spread of Information
[ARC116E] Spread of Information
Score : points
Problem Statement
Takahashi Kingdom has towns, called Town through . There are roads in this kingdom. The -th road connects Town and Town bidirectionally. For any two towns and , it is possible to get from Town to Town 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 towns.
Assume that Takahashi finishes transmitting the information at time . Then, for each , the following happens:
- For towns and directly connected by a road, if has already received the information at time but has not, receives it at time .
Takahashi wants to choose the 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.
- For any two towns and , it is possible to get from Town to Town by traversing some roads.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5 2
1 2
2 3
3 4
4 5
1
If Takahashi directly transmits the information to Town and , Town receives it at time , respectively. In this case, the information is spread all over the kingdom at time . 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