Gold snack sticks on Cebu
InterviewTime limit1sMemory limit256 MB
Given a weighted undirected graph, find the maximum over all routes from s to e of the minimum edge weight on the route.
- Level
Medium6 of 10
- Topics
- Graph, Union-find, Greedy
- Solved
- No attempts yet
Problem
Hyebin and Sungi took a trip to an island near Cebu. The island is a set of houses floating on the sea, joined by oak bridges. Sungi arranged a surprise event with the island keeper, who is keeping Hyebin at the event site.
On the day of the event Sungi wants to carry snack sticks made of gold to that site. Every bridge has a weight limit on how much can cross it at once. Throwing away expensive gold on the way would be a waste, so Sungi wants to leave home carrying exactly as many sticks as can reach Hyebin's house in one trip.
Sungi picks any route and may pass through the same house or the same bridge more than once. Whatever route is taken, the smallest weight limit among the bridges on that route decides how much can be carried at once. Given the house numbers and the weight limit of every bridge, find the largest number of gold sticks Sungi can bring to Hyebin.
One gold stick weighs 1, and Sungi's own weight is not counted.
Input
The first line has the number of houses () and the number of bridges ().
The second line has the number of the house Sungi starts from, , and the number of the house Hyebin is in, . (, )
Each of the next lines describes one bridge as a house number (), a house number (), and a weight limit (), meaning house and house are joined by a bridge whose weight limit is . A bridge can be crossed in both directions.
Several bridges may join the same pair of houses, and a bridge with equal to may appear.
Output
Print on the first line the largest number of gold sticks that can be carried in one trip from Sungi's house to Hyebin's house. If no route joins the two houses, print 0.
Hint
In the first example the best route crosses (limit 4), (limit 4), and (limit 3). The amount this route carries at once is .