Travel by one person
Time limit:1000 ms
Memory limit:32768kb
64bit Io format:% I64d & % i64usubmit status
Description
Although caoer is a luchi (that is, a person who has been in Hangzhou for more than a year will still be lost on campus, Khan ~), However, caoer still enjoys traveling, because he will meet many people (Prince Charming, ^ 0 ^) on the road. Many things can enrich his experience, you can also see beautiful scenery ...... Caoer wants to go to many places. She wants to go to the Tokyo Tower to see the night view, go to Venice to see the movie, go to Yangmingshan to see the taro, go to New York to see the pure snow scene, go to Paris to drink coffee and write, visit Meng jiangnv in Beijing ...... The winter vacation is approaching. You can't waste it for such a long period of time. You must give yourself a good vacation, but you can't waste your training, therefore, caoer decided to go to a desired place in the shortest time! Because caoer's home is in a small town without passing by train, she can only go to a nearby city to take a firecar (poor Ah ~).
Input
There are multiple groups of input data. The first row of each group is three integers t, s, and D, indicating that there are t routes and S are adjacent cities in cao'er's home, there are d places to go;
Then there are t rows. Each row has three integers A, B, and time, indicating that the driving distance between cities A and B is time hour. (1 = <(A, B) <= 1000; there may be multiple routes between A and B)
The next line t + 1 contains the number of S, indicating the city connected to cao'er's home;
The next line T + 2 has the number D, which indicates that the grass wants to go to the place.
Output
Output the shortest time for a particular city.
Sample Input
6 2 31 3 51 4 72 8 123 8 44 9 129 10 21 28 9 10
Sample output
9
# Include <stdio. h> # include <string. h> # define FF 999999; int Max; int map [1001] [1001]; int VT [1001] = {0}; int dis [1001]; void Dijkstra () {int I, j, POs, K, min; For (k = 0; k <Max; k ++) {pos = 0; min = ff; for (I = 0; I <MAX + 1; I ++) {If (Vt [I] = 0 & dis [I] <min) {pos = I; min = dis [I] ;}} VT [POS] = 1; for (I = 0; I <MAX + 1; I ++) {If (Vt [I] = 0 & dis [I]> dis [POS] + map [I] [POS]) {dis [I] = dis [POS] + map [I] [POS] ;}}} int main () {int T, S, D, DD, AA [1005]; int I, j; int mm, KK; int U, V, W; while (scanf ("% d", & T, & S, & D )! = EOF) {for (I = 0; I <1001; I ++) {for (j = 0; j <1001; j ++) {map [I] [J] = FF ;}} memset (Vt, 0, sizeof (VT); max =-1; // Max is used to determine the maximum data range for (I = 0; I <t; I ++) {scanf ("% d", & U, & V, & W); If (Map [u] [v]> W) {map [u] [v] = W; map [v] [u] = W;} If (u> MAX) {max = u;} If (V> MAX) {max = V ;}} for (I = 0; I <s; I ++) {scanf ("% d", & DD); map [0] [DD] = 0 ;} mm = ff; For (j = 0; j <D; j ++) {scanf ("% d", & aa [J]); // input endpoint} for (I = 0; I <MAX + 1; I ++) {dis [I] = map [0] [I];} VT [0] = 1; Dijkstra (); int min = ff; for (I = 0; I <D; I ++) {If (min> dis [AA [I]) min = dis [AA [I];} printf ("% d \ n", min );} return 0 ;}