Choose the Best Route
Problem Description
One day, Qiqi wants to take a bus to visit one of her friends.
Because Qiqi gets carsick very easily, she wants to get to her friend`s house as quickly as possible.
You are given a city public transportation route map, which includes the bus stops and the specific distribution of bus routes in the city.
The city contains n bus stops (numbered 1 to n) and m bus routes.
Each bus route is one-way, going directly from one bus stop to another. There may be multiple bus routes between the same two stops.
Qiqi`s friend lives near bus stop s.
Qiqi can transfer to other buses at any stop.
Please find the minimum time Qiqi needs to reach her friend`s house (the bus stop near it).
Input Format
The input contains multiple test cases.
For each test case:
The first line contains three integers n, m, s, representing the number of stops, the number of bus routes, and the number of the stop near her friend`s house respectively.
The next m lines each contain three integers p, q, t, indicating there is a bus route from stop p to stop q that takes time t.
The next line contains an integer w, indicating that there are w stops near Qiqi`s home. She can choose any one of them as the starting stop.
The following lines contains w integers, representing the numbers of the w stops near Qiqi`s home.
Output Format
For each test case, output an integer representing the minimum time required.
If it is impossible to reach the friend`s stop, output -1.
Each result occupies a single line.
Data Range
n ≤ 1000, m ≤ 20000
1 ≤ s ≤ n
0 < w < n
0 < t ≤ 1000
Input Sample:
5 8 5
1 2 2
1 5 3
1 3 4
2 4 7
2 5 6
2 3 5
3 5 1
4 5 1
2
2 3
4 3 4
1 2 3
1 3 4
2 3 2
1
1
Output Sample:
1
-1
Comments
.