#P1111. 修复公路
修复公路
Description
Given the number of villages and the number of roads in region A. The roads are bidirectional. You are told which two villages each road connects and when this road will be completed. Find the earliest time when any two villages can travel between each other, i.e., the earliest time when for any pair of villages there exists at least one completed path (possibly consisting of multiple roads).
Input Format
The first line contains two positive integers .
Then the next lines follow. Each line contains three positive integers , indicating that this road connects villages and , and it will be completed at time .
Output Format
If, after all roads are completed, there still exist two villages that cannot travel between each other, output . Otherwise, output the earliest time when any two villages can travel between each other.
4 4
1 2 6
1 3 4
1 4 5
4 2 3
5
Hint
, .
Translated by ChatGPT 5
京公网安备 11011102002149号