#K64287. Minimum Maximum Travel Time in Railway Network
Minimum Maximum Travel Time in Railway Network
Minimum Maximum Travel Time in Railway Network
You are given a railway network with n stations and m railway tracks. Each track connects two stations and has an associated travel time. Your task is to choose some of these tracks such that all stations in each connected component are connected, and the maximum travel time among the chosen tracks is minimized. In other words, if you build a Minimum Spanning Tree (MST) (or forest, if the network is disconnected), you need to report the weight of the heaviest edge used.
This problem can be solved using Kruskal's algorithm with a union-find data structure. The answer is the minimum possible value of the maximum travel time between two connected stations.
Note: In case the network is disconnected, compute the MST for each connected component and output the maximum travel time among all MST edges.
inputFormat
The input is given from standard input (stdin) and has the following format:
The first line contains two space-separated integers n and m — the number of stations and the number of railway tracks.
Each of the next m lines contains three integers u, v, and w, representing a railway track between station u and station v with a travel time of w.
outputFormat
Output to standard output (stdout) a single integer — the minimum possible value of the maximum travel time between any two connected stations after choosing the optimal set of tracks.## sample
5 6
1 2 4
2 3 4
2 4 6
3 5 7
4 5 8
1 5 10
7