Trucking
Time limit3sMemory limit128 MB
For each graph case, find the largest cargo height allowing a route, then the shortest route length among routes that allow it.
- Level
Medium5 of 10
- Topics
- Graph, Shortest path, Heap, Greedy
- Solved
- No attempts yet
Problem
A local trucking company wants to transport goods on a cargo truck from one place to another. On each trip it wants to carry as much cargo as possible. Unfortunately the shortest route cannot always be used: some roads have obstacles (such as bridge overpasses or tunnels) that limit the height of the cargo that can pass. So the company first wants to carry as much as possible on a trip, and then, among all routes that can carry that amount, choose the shortest one.
For a given cargo truck, maximizing the height of the cargo is equivalent to maximizing the amount of cargo carried. For safety, the truck itself also has a height limit that cannot be exceeded.
In other words, the maximum height of cargo that can be carried is the smaller of the truck's height limit and the minimum height limit among the roads on the route. First find this maximum height, then find the length of the shortest route that uses only roads which allow cargo of that height.
Input
The input consists of several cases. Each case begins with two integers and on one line, separated by a space: the number of cities and the number of roads . There are at most 1000 cities, numbered from 1. This is followed by lines, each giving the two city numbers connected by a road, the maximum height allowed on that road, and the length of that road. The maximum height of each road is a positive integer, except that a height of means the road has no height limit. The length of each road is a positive integer at most 1000. Every road can be travelled in both directions, and there is at most one road connecting any distinct pair of cities. Finally, the last line of each case gives the start and end city numbers together with the height limit of the cargo truck (a positive integer). The input terminates when .
Output
For each case, first print Case X:, where is the case number starting from 1. If the destination is reachable, print maximum height = H on the next line (where is the maximum cargo height), and print length of shortest route = L on the following line (where is the length of the shortest route). If the end city cannot be reached from the start city, print cannot reach destination on the line after Case X:. Print a blank line between the output of consecutive cases.