Problem G
Slow Leak
You are an avid cyclist and bike every day between your home and school. Usually, your ride is uneventful and you bike along the shortest path between home and school. After school this afternoon you realized you have a slow leak in your bike tire—the tire can hold some air, but not for long. Refilling the tire allows you to ride your bike for some distance, after which your tire goes flat again and it becomes impossible to ride any further (and you refuse to walk your bicycle).
Luckily for you, your city has installed several bike repair stations at intersections throughout town where you can refill your tire and bike again until the tire goes flat. There’s a repair station at your school too, so that you can fill up your tire before you start on your trip home.
You’ve calculated how far you can bike before your tire runs out of air and you know the layout of your town, including all the intersections, distances between them, and the locations of the repair stations. What is the shortest possible trip from school to your home that you can take without becoming stuck due to a flat tire? (You do not become stuck if you roll into a repair station, or your home, at the exact same time as your tire goes flat.)
![\includegraphics[width=0.7\textwidth ]{samples.pdf}](/problems/slowleak/file/statement/en/img-0002.png)
Input
The first line of input contains four integers
The second line of input contains
The next
Output
Print the minimum total distance you need to travel to reach home from school without getting stuck due to a flat tire. If the trip is not possible, output the word stuck on a single line instead.
It is guaranteed that if the trip is possible, the minimum
distance
Sample Explanation
In the first sample input, if your tire did not have a leak
then the shortest path home would have a distance of
In the second sample input, if your tire did not have a
leak, then the shortest path home would have a distance of
Sample Input 1 | Sample Output 1 |
---|---|
6 7 2 4 2 5 1 2 4 1 3 5 2 3 3 3 4 2 3 5 1 4 6 4 5 6 4 |
12 |
Sample Input 2 | Sample Output 2 |
---|---|
6 7 2 10 2 5 1 2 1 1 3 2 2 3 1 3 4 8 4 5 3 4 6 2 5 6 1 |
stuck |