Heavy Transportation
Time limit1sMemory limit128 MB
Find the maximum weight that can travel from crossing 1 to crossing n, defined as the path whose smallest street limit is as large as possible.
- Level
Medium5 of 10
- Topics
- Graph, Minimum spanning tree, Greedy, Union-find
- Solved
- No attempts yet
Problem
Hugo Heavy is expanding his business. He has to move a giant steel crane from where his customer built it to where it is needed, and every street along the route must be able to carry the crane's weight.
He has a map of the city listing every street and bridge together with its weight limit, but he has no idea how heavy the crane may become for the route to still support it. Working that out is your job.
The city has crossings, numbered from to . Streets connect the crossings, and each street has a maximum weight it can carry. Find the maximum weight that can be transported from crossing (Hugo's place) to crossing (the customer's place). This is the value of the route from to whose smallest street weight limit is as large as possible. Every street can be travelled in both directions, and you may assume at least one route from to always exists.
Input
The first line contains the number of scenarios (city maps).
Each scenario starts with a line containing two integers and : the number of crossings () and the number of streets. Each of the next lines contains three integers , , and , describing a street between crossings and with maximum allowed weight (). There is at most one street between any pair of crossings.
Output
For each scenario, print a line Scenario #i:, where is the scenario number starting at , followed by a line containing the maximum weight that can be transported from crossing to crossing . Print a blank line between consecutive scenarios.