OlveraeUNSW
Back to problems
COMP2521

MST: Largest Edge in the MST

MST: the largest edge weight in the MST (bottleneck edge)

Build the MST with Kruskal again, but this time print the weight of the largest edge chosen in the MST (the "bottleneck edge"). Union-find and sorting are provided; complete the loop.

Method: run Kruskal as for total weight, but track the maximum w among edges you accept.

Hint: because edges are processed in ascending order, the last accepted edge is usually the largest; to be safe, do if (w > maxw) maxw = w; on each accepted edge.
Pitfall: take the max only over edges actually added to the MST (find(u)!=find(v)), not the skipped cycle edges.

Input

  • Line 1: V E (connected).
  • Next E lines: u v w, undirected weighted edge.

Output

  • One line: the largest edge weight in the MST.

Example: input 4 4 / 0 1 1 / 1 2 2 / 2 3 3 / 0 3 4 -> 3 (MST chose weights 1, 2, 3; the largest is 3).

Samples

stdin
4 4
0 1 1
1 2 2
2 3 3
0 3 4
expected
3
stdin
5 7
0 1 2
0 3 6
1 2 3
1 3 8
1 4 5
2 4 7
3 4 9
expected
6
c-dcc
14