#P11966. Shortest Time to School

    ID: 14076 Type: Default 1000ms 256MiB

Shortest Time to School

Shortest Time to School

In city C, there is an undirected graph with nn nodes and mm edges. The nodes are numbered 1,2,,n1, 2, \ldots, n, and for each edge ii (1im1 \leq i \leq m), it connects node uiu_i and node viv_i with a length of lil_i meters. The school is located at node ss. There are qq students. For the ii-th student, his/her home is at node hih_i, and he/she walks at a speed of 1 meter per second. Your task is to compute the minimum number of seconds required for each student to reach the school, assuming they take the shortest possible path.

inputFormat

The first line contains three integers nn, mm, and ss (1sn1 \leq s \leq n).

Each of the next mm lines contains three integers uiu_i, viv_i, and lil_i, describing an undirected edge between nodes uiu_i and viv_i with length lil_i meters (1ui,vin1 \leq u_i, v_i \leq n, li>0l_i > 0).

The next line contains an integer qq, the number of queries (i.e., the number of students).

Each of the next qq lines contains one integer hih_i, representing the home node of the ii-th student.

outputFormat

Output qq lines. The ii-th line should contain one integer: the minimum number of seconds required for the ii-th student to reach school (i.e., the shortest distance in meters from node hih_i to node ss).

sample

4 4 1
1 2 5
2 3 5
3 4 5
1 4 20
3
1
2
4
0

5 15

</p>