Problem description although caoer is a luchi (that is, the 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 take a train to the neighboring city ~).
There are multiple groups of input data. The first line of each group is three integers t, s, and D, indicating that there are t routes and S are adjacent to cao'er's city, there are d places to go in the grass; then there are t rows, each line has three integers a, B, 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 has the number of S, it indicates the city connected to caoer's home; the number of D in the second line T + 2 indicates that caoer wants to go to the place.
Output outputs the shortest time for 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
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define MX 1000000using namespace std;int t;int m[1005][1005],D[1000],S[1000];int p[1005],num[10005];int dstl(int s){ memset(p,0,sizeof(p)); for(int i=1;i<=1000;i++) { num[i]=m[s][i]; } num[s]=0; p[s]=1; for(int i=1;i<=1000;i++) { int k,mi=MX; for(int j=1;j<=1000;j++) { if(!p[j]&&num[j]<mi) { mi=num[j]; k=j; } } p[k]=1; if(mi==MX)return MX; for(int j=1;j<=1000;j++) { if(!p[j]&&num[j]>num[k]+m[k][j]) num[j]=num[k]+m[k][j]; } }}int main(){ int s,d; int a,b,time; while(scanf("%d%d%d",&t,&s,&d)!=EOF) { for(int i=1;i<=1000;i++) for(int j=1;j<=1000;j++) m[i][j]=MX; for(int i=1;i<=t;i++) { scanf("%d%d%d",&a,&b,&time); if(time<m[a][b]) m[a][b]=m[b][a]=time; } for(int i=0;i<s;i++) scanf("%d",&S[i]); for(int i=0;i<d;i++) scanf("%d",&D[i]); int mi=MX; for(int i=0;i<s;i++) { dstl(S[i]); for(int j=0;j<d;j++) { if(mi>num[D[j]])mi=num[D[j]]; } } printf("%d\n",mi); } return 0;}