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.
Medium7Shortest pathGreedyNo attempts yetTime limit5sMemory limit512 MBA free shuttle service runs M 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 i is one integer between ai and bi, 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.
| ID | Start city | Destination city | Length |
|---|---|---|---|
| 1 | Mountain View | London | 100 to 1000 |
| 2 | Mountain View | Paris | 500 to 5000 |
| 3 | Paris | London | 400 to 600 |
| 4 | Paris | Moscow | 500 to 5000 |
| 5 | Moscow | London | 1 to 10000 |
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.
The first line holds the number of test cases T. The first line of each test case holds three positive integers N, M and P. N is the number of cities, numbered 1 to N. M is the number of routes, and P is the number of routes on the path I wrote down.
Each of the next M lines holds four integers ui, vi, ai, bi. There is a one way route from city ui to city vi whose length is an integer between ai and bi, inclusive. The routes are numbered 1 to M in the order they appear in the input.
The last line holds P distinct integers between 1 and M: the numbers of the routes I take, in order.
Limits
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.