#P15043. [UOI 2022 II Stage] 图
[UOI 2022 II Stage] 图
Problem Description
The city where Xonia lives consists of intersections, which are connected by undirected roads.
The intersections are numbered from to . The roads are also numbered from to . The -th road connects intersections and , and its length is .
It is known that using the existing roads, you can travel from any intersection to any other intersection. Between any two intersections, there is at most one road. There is no road that connects an intersection to itself.
Let be the length of the shortest path between intersections and .
Xonia wants to find two intersections and in the city such that is the maximum among all possible pairs .
Input Format
The first line contains two integers and (, ), representing the number of intersections in the city and the test group number, respectively.
The next lines each contain three integers , , and (, ).
It is guaranteed that using the roads you can travel from any intersection to any other intersection.
It is guaranteed that there is no road that connects an intersection to itself.
It is guaranteed that between any two intersections there is at most one road.
Output Format
Output the maximum value of over all pairs of intersections .
4 0
1 2 1
1 3 2
2 3 3
2 4 3
6
Hint
Sample Explanation
Explanation for the first sample:
Therefore, the maximum .
Scoring
- (22 points): The graph structure is a simple cycle.
- (17 points): .
- (24 points): The length of each cycle in the graph does not exceed 1000.
- (9 points): .
- (28 points): No additional constraints.
Translated by DeepSeek V3.
Translated by ChatGPT 5