Baltic Olympiad in Informatics: 2002 Day 1, Problem 1
In our busy world, we are not usually interested in taking the shortest path, but rather the path that takes the shortest time. When driving a car, this means that the speed limits on different roads are crucial. Imagine now that some speed limit signs are missing. Since you cannot expect the driver to know speed limits by heart, the only reasonable conclusion is that whatever speed limit he/she obeyed before will still hold after passing a missing sign. You are to write a program that calculates the fastest path by taking advantage of the missing signs.
You are given a description of the road network in a highly motorized area. To make
things easier the network consists of crossings and roads. Every road is one-way,
connects exactly two crossings and has at most one speed limit sign, located in the
beginning of the road. For any two crossings
Constraints
Input Specification
The first line of input consists of three space-separated integers
Each of the following
Output Specification
Output one single line of space-separated integers, describing the crossings you pass on the fastest possible path from
Sample Input
6 15 1
0 1 25 68
0 2 30 50
0 5 0 101
1 2 70 77
1 3 35 42
2 0 0 22
2 1 40 86
2 3 0 23
2 4 45 40
3 1 64 14
3 5 0 23
4 1 95 8
5 1 0 84
5 2 90 64
5 3 36 40
Sample Output
0 5 2 3 1
Explanation for Sample
The required time is in this case
Comments