DescriptionAlthough the grass is a road fetish (that is, in Hangzhou electric for more than a year, incredibly still will be lost in the campus, Khan ~), but the grass is still very fond of travel, because in the journey will meet a lot of people (Prince Charming, ^0^), a lot of things, but also to enrich their experience, but also to see beautiful scenery ... Grass wants to go to many places, she wants to go to the Tokyo Tower to see the night scene, to Venice to see movies, to see the Taro on Yangmingshan, go to New York pure snow, go to Paris to drink coffee letter, to Beijing to visit Meng Jiangnu ... See the winter vacation is coming, so a large period of time, can not be wasted ah, must give yourself good put a fake, but also can not waste training ah, so grass son decided in the shortest time to a place where they want to go! Because the house of grass is in a small town, there is no train passing by, so she can only go to the neighboring city by train (poor Ah ~).InputThe input data has more than one group, the first line of each group is three integers t,s and D, indicating that there is a T road, and the grass son of the city adjacent to the cities have s, where the grass wants to go there are D;
Then there is a T-line, each line has three integer a,b,time, indicating that the drive between A and B cities is time hours; (1=< (A, B) there may be multiple paths between <=1000;a,b)
The next line of T+1 is the number of S, which indicates the city connected with the grass family;
The next line of T+2 has a number D, indicating that the grass wants to go to the place.Output
The shortest time the grass can go to a favorite city.
Sample Input
6 2 31 3 51 4 72 8 123 8 44 9 129 10 21 28 9 10
Sample Output
9
1#include <cstdio>2#include <algorithm>3#include <string.h>4 #defineINF 0XFFFFFFF5 using namespacestd;6 intmax0,map[10100][10100],flag[1010],len[1010];7 voidF1 ()8 {9 inti,j;Tenmemset (Flag,0,sizeof(flag));//clear 0 for marker array Oneflag[0]=1; A for(i =1; I <= max0; i++) - { -len[i]=map[0][i];//Len[i] represents the distance from the 0 node to the I node the } - for(i =0; i < max0; i++) - { - intm=inf,k=-1; + for(j =1; J <= Max0; J + +) - { + if(!flag[j] && Len[j] <M) A { atM=LEN[J];//find the closest point to the 0 node -k=J; - } - } -flag[k]=1; - for(j =1; J <= Max0; J + +) in { - if(!flag[j] && len[j] > len[k]+Map[k][j]) to { +LEN[J]=LEN[K]+MAP[K][J];//Compare the distance between the 0 node to the J node and the distance from the 0 node to the K node to the J node to record a small value - } the } * } $ }Panax Notoginseng intMain () - { the intt,s,d,i,j,x,a,b,c; + while(SCANF (" %d%d%d", &t,&s,&d)! =EOF) A { the for(i =0; I <=1001; i++)//the range of I may be greater than 1000, so the upper limit is greater than + { - for(j =0; J <=1001; J + +) $ { $Map[i][j]=inf;//the distance from the initial I to J - } - } themax0=0; - for(i =0; I < T; i++)//Enter the relationship of the cityWuyi { thescanf" %d%d%d",&a,&b,&c); - if(Map[a][b] >c) Wu { -map[a][b]=map[b][a]=C; About } $Max0=max (Max0,max (A, b));//record the largest city number - } -max0++; - for(i =0; I < S; i++) A { +scanf"%d",&x); themap[0][x]=0;//0 is the starting point, and the distance from the starting point to the neighboring city is set to 0 - } $ for(i =0; I < D; i++) the { thescanf"%d",&x); themap[x][max0]=0;//make max0 the end, the destination to go to the city distance of 0 the } - F1 (); inprintf"%d\n", len[max0]); the } the About}
Hangzhou Electric 20,661 Person's travel