Gon and Greed Island

0

0 votes
Easy
Problem

The Greed Island consists of N cities and M bidirectional roads. Gon starts his quest at city 1 and has to reach city N by travelling the shortest amount of distance. But there is a catch, he must visit K special cities before reaching the city N. Since he is not very good at such calculations, he asked Killua and you to help him figure out the shortest amount of distance to traveled.

enter image description here

INPUT:
The first line contains two integers N and M.
Next M lines contain three integers each u,v,c describing a bidirectional road between u and v and distance c.
Next line contains an integer K.
Next line contains K space separated integers A[i],1iK, the cities which must be visited before reaching city N.

CONSTRAINTS:
1N200
1M500
1K10

OUTPUT:
The shortest distance traveled to reach city N.

Sample Input
5 7
4 1 1
3 2 8
5 3 1
4 5 9
3 4 9
2 4 5
1 2 9
2
3 2
Sample Output
15
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The graph for sample input:
enter image description here

Contributers:
Editor Image

?