Widening of Channels
Time limit1sMemory limit128 MB
Given a weighted undirected graph, find the minimum number of edges to widen to width k so that every pair of vertices is connected.
- Level
Medium6 of 10
- Topics
- Graph, Union-find, Greedy, Sorting
- Solved
- No attempts yet
Problem
In the country of Waterland there are lakes, numbered from to , and channels connecting them. Each channel has a known width (in meters), and every channel can be navigated in both directions. It is guaranteed that a boat one meter wide can reach every lake starting from lake .
Write a program that computes the minimum number of channels that must be widened so that a boat meters wide can travel between every pair of lakes. A boat can pass through a channel only if its width is less than or equal to the width of the channel; that is, a channel of width can be used when . Widening a channel raises its width to at least .
Input
The first line contains two integers and (, ).
Each of the next lines contains three integers , , and , meaning that there is a channel of width between lakes and (, ).
The last line contains the integer ().
Output
Print a single integer: the minimum number of channels that must be widened.