#C11544. Minimum Maximum Weight Limit in Cable Car Network
Minimum Maximum Weight Limit in Cable Car Network
Minimum Maximum Weight Limit in Cable Car Network
You are given a network of C campsites and N cable cars connecting these campsites. Each cable car is described by a triple \( (u, v, w) \) where campsites \( u \) and \( v \) are connected and \( w \) is the weight limit of that cable car.
Your task is to choose a subset of these cable cars such that all campsites become connected (i.e. form a spanning tree). Among all possible spanning trees, you must minimize the maximum weight limit used in that tree. In other words, if the selected cable cars in the spanning tree have weight limits \( w_1, w_2, \ldots, w_{C-1} \), you need to minimize \( \max\{w_1, w_2, \ldots, w_{C-1}\} \).
If there are no cable cars provided, output 0.
Input Format: The first line of input contains two integers \( C \) and \( N \). Each of the following \( N \) lines contains three integers \( u \), \( v \), and \( w \), representing a cable car between campsites \( u \) and \( v \) with weight limit \( w \).
Output Format: Output a single integer denoting the minimum possible maximum weight limit among the cable cars selected in the spanning tree.
inputFormat
The first line contains two space-separated integers \( C \) (the number of campsites) and \( N \) (the number of cable cars). Each of the next \( N \) lines contains three space-separated integers \( u \), \( v \), and \( w \) representing a cable car from campsite \( u \) to campsite \( v \) with a weight limit of \( w \).
outputFormat
Output a single integer which is the minimum possible maximum weight limit among the cable cars chosen to connect all campsites.
## sample4 5
1 2 10
1 3 30
2 3 40
3 4 20
4 2 50
30