#P5536. 【XR-3】核心城市
【XR-3】核心城市
Problem Description
Country X has cities and roads of length . Each road connects two cities, and any two cities can reach each other through some roads. Obviously, the cities and roads form a tree.
The king of Country X decides to designate cities as the core cities of Country X, and the remaining cities are non-core cities. These core cities must satisfy the following two conditions:
- These cities can reach each other pairwise via roads without passing through any non-core city.
- Define the distance from a non-core city to the core cities as the minimum value among its distances to the core cities.
To measure traffic conditions, the king invented the traffic congestion level, which is the maximum value among the distances from all non-core cities to the core cities.
The problem is: how should we choose the core cities to minimize the traffic congestion level? Output the minimum possible traffic congestion level that satisfies the conditions.
Input Format
The first line contains positive integers .
The next lines each contain positive integers , meaning there is a road of length between city and city .
Constraints:
- .
- , and it is guaranteed that the cities and roads form a tree.
Output Format
One line with one integer, representing the minimum traffic congestion level that satisfies the conditions.
6 3
1 2
2 3
2 4
1 5
5 6
1
Hint
[Sample Explanation]
Designate cities as the core cities. Then the distances from the other non-core cities to the core cities are all , so the answer is .
Translated by ChatGPT 5