CCO '11 P2 - Vampire Tunnels
View as PDFCanadian Computing Competition: 2011 Stage 2, Day 1, Problem 2
You are a vampire, and you want to travel from some point  to another point 
. You may travel in the sunshine above ground or avoid the sunshine by traveling underground via certain tunnels. You have mapped out the area you wish to travel, and have found some secret tunnels between some points, some other points that you can walk between above ground. Both the tunnels and above ground paths are bidirectional. Given that you can't be exposed to the sunlight for more than 
 seconds in total 
, you want to minimize the total travel time (given that you have a constant velocity of 
 unit of distance per second).
Input Specification
On the first line of input, you have the number , the maximum number of seconds that you can be exposed to the sun. On the next line is the number 
 
, which is the number of points, and the number 
 
, which is the number of connections between these 
 points, separated by one space.
The next  lines each contain information about the connections between points. Specifically, each of these lines contain four integers: 
 (one end point of a connection) 
, 
 (the other end point of a connection) 
, 
 (the distance between 
 and 
, 
), 
 (indicate whether this is underground or above ground: 
 indicates it is above ground, and 
 indicates there is a tunnel between 
 and 
).
Note: for  of the marks for this question, you can assume 
.
Output Specification
The output is one integer, which is the minimum amount of time required to get from point  to point 
, with the constraint that there are not more than 
 seconds of exposure to the sun. If there is no possible path which satisfies the constraint, output 
.
Sample Input
3
4 6
0 1 3 1
0 2 4 1
0 3 10 1
1 2 3 0
1 3 1 1
2 3 3 0
Sample Output
9
Explanation for Sample Output
The path  gives a total travel time of 
 seconds with 
 seconds of exposure to the sun. All other paths either required more time (e.g., 
 uses 
 seconds) or overexpose to the sun (e.g., 
 exposes to the sun for 
 seconds).
Comments
Note that you can't be exposed to the sunlight for MORE THAN
 seconds; if you are exposed for exactly 
 seconds you will be fine.
Lower memory usage in python
I AC all test cases except number 6, which I MLE by a somewhat small margin. Is there any way to make my code use less memory?