Vampire Tunnels
Time limit2sMemory limit512 MB
Find the shortest path from node 0 to N-1 where the total length of above-ground edges is at most S.
- Level
Medium6 of 10
- Topics
- Shortest path, Dynamic programming, Graph
- Solved
- No attempts yet
Problem
You are a vampire, and you want to travel from point 0 to point . You may walk above ground, exposed to sunlight, or avoid the sun by travelling underground through secret tunnels. Both the tunnels and the above-ground paths are bidirectional.
You move at a constant speed of unit of distance per second, so travelling along a path of length takes seconds. You may be exposed to sunlight for at most seconds in total. Minimize the total travel time from point 0 to point while respecting this limit.
Input
The first line contains the integer (), the maximum number of seconds you may be exposed to the sun.
The second line contains two integers () and (), separated by a single space: the number of points and the number of connections. The points are numbered from 0 to .
Each of the next lines contains four integers , , , describing one connection:
- , (, ): the two endpoints of the connection
- (): the distance (travel time) between and
- : if the connection is above ground (exposed to sun), or if it is a tunnel (underground, no sun exposure)
Output
Output a single integer: the minimum time needed to travel from point 0 to point while spending at most seconds exposed to the sun. If no path satisfies this constraint, output .