#P40019. 2019 ICPC NA Qualifier Contest I - Slow Leak

2019 ICPC NA Qualifier Contest I - 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.)

image.png

Figure 1: An illustration of the two sample inputs.

输入格式

The first line of input contains four integers nn, mm, tt, and dd, satisfying 2n5002 \le n \le 500, 0mn(n1)/20 \le m \le n(n-1)/2, 0tn0 \le t \le n and 0d2310 \le d \le 2^{31}. The value nn represents the number of intersections in the city, mm represents the number of roads in the city, tt is the number of repair stations and dd is the distance that you can bike (starting with a fully inflated tire) before your tire goes flat again. The intersections are numbered from 11 to nn. Your school is at intersection 11 and your home is at intersection nn.

The second line of input contains tt integers, with values between 22 and n1n-1, inclusive. These are the intersections where the repair stations are located (excluding your school’s repair station). All integers on this line are unique.

The next mm lines represent the roads in your town. Each has three integers i,j,ki, j, k, where 1ijn1 \le i \le j \le n, and 0k2310 \le k \le 2^{31}. These three integers represent that there is a direct road from intersection ii to intersection jj of length kk. Roads can be traveled in either direction. There is at most one road between any two intersections.

输出格式

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 DD satisfies 0D2310 \le D \le 2^{31}.

样例

样例输入 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

样例输出 1

12

样例输入 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

样例输出 2

stuck

数据范围与提示

In the first sample input, if your tire did not have a leak then the shortest path home would have a distance of 99, going from the school through intersections 33 and 55. However, due to the leak, you can only travel a distance of 44 before you need to refill the tire, requiring you to use the repair stations at intersections 22 and 55, for a total distance of 1212.

In the second sample input, if your tire did not have a leak, then the shortest path home would have a distance of 1212. But since your tire only lasts for a distance of 1010, there’s no path where your bike tire will not go flat somewhere along the way. Even when using repair station at intersection 22, you get stuck before you can reach either your home or the repair station at intersection 55.