Nearest Play-Ground

0

0 votes
Medium
Problem

There are N cities and M bidirectional roads connecting the cities. There is some travellng time associated with each road. Out of the N cities P cities contain play-grounds. People living in the cities travel to some other city with play-ground.

You will be asked Q queries, each query will contain single integer,denoting the city number, where the person lives and wants to travel to the city with the play-ground. You need to find the minimum time taken to reach that city.

If it is not possible to reach the city print "-1".

 

INPUT:

First line will contain four integers N,M,P,Q denoting number of cities, number of edges, number of cities with playground, number of queries, respectively. 

Next line contains P integers, denoting id of the cities with playgrounds.

Each of the next M lines contain, three integers S,D and W, denoting there is a road between the cities S and D, travelling time is W minutes.

Each of the next Q lines contain, single integer, id of the city the person lives and wants to travel to the city with the play-ground in minimum time.

 

OUTPUT:

For each query output a single line containing the minimum travelling time to reach the city with play-ground.

 

CONSTRAINTS:

2<=N<=105 

1<=M,Q<=105

1<=P,S,D<=N

1<=W<=109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

City 1 has play-ground, so person at city 1 has to travvel for 0 mins. People at city 2 has to travel for 2mins. People at city 3 has to trravel through city 2, total travel time 2+3=5mins

Editor Image

?