#C3788. Minimum Maximum Latency
Minimum Maximum Latency
Minimum Maximum Latency
On planet Zog, cities are connected by high-speed cables that have certain latency values. There are P cities and Q possible cables. Each cable connects two cities and has a latency value, given as a triple (a, b, l). Your task is to choose a subset of these cables such that all cities are connected (i.e. the network is connected) and the maximum latency among the selected cables is minimized. This problem is equivalent to constructing a Minimum Spanning Tree (MST) and then reporting the weight of its heaviest edge. You can assume that the input graph is connected.
inputFormat
The input is read from standard input (stdin). The first line contains two integers P and Q separated by a space. Each of the following Q lines contains three integers a, b, and l, representing a cable that connects city a with city b that has latency l.
outputFormat
Output a single integer to standard output (stdout) which is the minimum possible value of the maximum latency among all cables chosen to connect the cities.
## sample4 5
1 2 3
1 3 5
2 3 4
2 4 8
3 4 2
4