Are We Lost Yet? (Large)
Time limit5sMemory limit512 MB
Check each route of a given path in a graph with interval edge lengths and report the first one that cannot lie on a shortest path from city 1 to city 2.
- Level
Medium7 of 10
- Topics
- Shortest path, Greedy
- Solved
- No attempts yet
Problem
A free shuttle service runs one way routes between cities. For each route you know which city it leaves and which city it enters, but you do not know its exact length. The length of route is one integer between and , inclusive.
I want to travel from city 1 to city 2, and I have written down the routes I plan to take, in order. My path finding is not as good as yours, so check my work.
Go through the routes of my path from the front. Assume that every earlier route was taken exactly as written. A route is fine if you can pick a length for every route inside its own range and pick a way to continue from the destination city of that route to city 2, so that what I have taken so far is the beginning of a shortest path from city 1 to city 2. Report the number of the first route that is not fine.
For example, take these five routes.
Suppose my path is Mountain View, Paris, Moscow, London, that is routes 2, 4 and 5. Route 2 is fine. If route 2 has length 500 and route 3 has length 400, then Mountain View to Paris to London is 900 while the direct route from Mountain View to London is at most 1000, so a shortest path starts with route 2. Route 4 is not fine. After Paris the trip still has to reach London, and Mountain View to Paris to Moscow to London is at least 1001 while route 1 is at most 1000. The answer is route 4.
Input
The first line holds the number of test cases . The first line of each test case holds three positive integers , and . is the number of cities, numbered 1 to . is the number of routes, and is the number of routes on the path I wrote down.
Each of the next lines holds four integers , , , . There is a one way route from city to city whose length is an integer between and , inclusive. The routes are numbered 1 to in the order they appear in the input.
The last line holds distinct integers between 1 and : the numbers of the routes I take, in order.
Limits
- The path I wrote down is a valid path that starts at city 1 and ends at city 2.
- Two cities can be joined by more than one route, and a route can start and end at the same city. My path may visit the same city more than once, but it never takes the same route twice.
Output
For each test case, print one line holding "Case #x: n", where x is the test case number starting from 1 and n is the number of the first route on my path that can never lie on a shortest path from city 1 to city 2. If there is no such route, print "Looks Good To Me" in place of n.