Wouldn't it be better to just earn garnets?
Time limit10sMemory limit128 MB
Find the second-fastest travel time from island 1 to island N over walks that may repeat bridges, and the largest garnet total among walks with that time.
- Level
Hard8 of 10
- Topics
- Shortest path, Dynamic programming
- Solved
- No attempts yet
Problem
Suckzoo is a contestant on the game show The Zzinius. Today's episode plays a game called Stepping Stones, and the rules are these.
- A map shows islands and bridges, and every bridge can be crossed in both directions.
- Each bridge takes a fixed amount of time to cross.
- Every time a player crosses a bridge, that player receives the number of garnets attached to that bridge.
- Every player starts on island 1, and players are ranked 1st, 2nd, ... in the order they reach island .
- A route from island 1 to island always exists.
- No player may cross bridges in exactly the same order as another player.
A player may pass through the same island many times and cross the same bridge many times.
Suckzoo has secretly allied with Youngseok, another contestant on the show. Today Suckzoo hands 1st place to Youngseok and takes 2nd place himself. Arriving tied for 1st place also counts as 2nd place. Youngseok only wants 1st place and does not care about garnets, while Suckzoo wants as many garnets as possible, because one garnet is worth a million won in cash. The two of them choose their routes before any other player.
None of the remaining players may overtake Suckzoo. So take every bridge order that leads from island 1 to island and sort those orders by total crossing time. Two orders that cross different bridges take two separate places even when their total time is equal. Suckzoo arrives at the second time on that list, and among the bridge orders that finish at that time he picks one that pays the most garnets.
Find the time at which Suckzoo reaches island and the number of garnets he has collected by then.
Input
The first line has the number of test cases ().
The first line of each test case has the number of islands () and the number of bridges ().
Each of the next lines has four integers , , , (, ). A bridge joins island and island , crossing that bridge takes time , and every crossing pays garnets. More than one bridge may join the same pair of islands.
The time and the garnet count you print fit in a signed 64-bit integer.
Output
For each test case, print one line in this format.
Game #i: Suckzoo ends game in time t, earning g garnet(s).
Here is the test case number starting at 1, is the time Suckzoo reaches island , and is the number of garnets he has collected by then.