In a directed graph with interval edge lengths, test each prefix of a suggested 1 to 2 route and report the first edge that cannot start a shortest path.
Medium7Shortest pathGraphBrute forceNo attempts yetTime limit5sMemory limit512 MBThe finals are in London, but a few of us went to Mountain View by mistake. A free shuttle service runs from Mountain View to London, so the trip is still possible.
The shuttle service consists of M one way routes between pairs of cities. For every route you know which city it leaves from and which city it goes to, but you do not know its exact length. All you know about route i is that its length is an integer between ai and bi, inclusive.
I have suggested one path of routes from Mountain View (city 1) to London (city 2), and you want to check my work. Could my path be a shortest path? If it could not, report the id of the first route on my path that can never be part of a shortest path, assuming every earlier route on my path was taken as suggested.
Stated precisely: take the first k routes of my path, in order. Route k passes the check if there is at least one way to choose an integer length for every route inside its range such that some shortest path from city 1 to city 2 starts with exactly those k routes in that order. Find the smallest k that does not pass and print the id of that route. If every k passes, print Looks Good To Me instead.
For example, suppose the shuttle routes are these.
| Id | Start city | Destination city | Route length |
|---|---|---|---|
| 1 | Mountain View | London | [100, 1000] |
| 2 | Mountain View | Paris | [500, 5000] |
| 3 | Paris | London | [400, 600] |
| 4 | Paris | Moscow | [500, 5000] |
| 5 | Moscow | London | [1, 10000] |
I suggest the path Mountain View → Paris → Moscow → London. Whatever the lengths turn out to be, the true shortest path is either the direct route from Mountain View to London or the path Mountain View → Paris → London. The second route on my path, route 4 from Paris to Moscow, is the first one that can never be part of a shortest path, so the answer is 4.
The first line of the input has the number of test cases, T. Each test case starts with a line holding three positive integers N, M and P. N is the number of cities, numbered 1 to N. M is the number of shuttle routes. P is the number of routes on my path from Mountain View (city 1) to London (city 2).
M lines follow. Line i holds four integers ui, vi, ai and bi, meaning there is a one way route from city ui to city vi whose length is an integer between ai and bi, inclusive. The routes get the ids 1 to M in input order.
The last line of the test case holds P distinct integers, the ids of the routes I take, in travel order.
Limits
For each test case print one line in the form Case #x: n, where x is the test case number starting from 1 and n is the id of the first route on my path that can never be part of a shortest path from city 1 to city 2. If there is no such route, print Looks Good To Me in place of n.