1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 #include<map> 6 using namespace std; 7 #define INF 0x3f3f3f3f 8 const int maxn=1001; 9 10 int T,S,D; 11 int want[maxn]; 12 int nex[maxn]; 13 map<int ,map<int ,int > >mymap; 14 15 bool visited[maxn]; 16 int dist[maxn]; 17 18 void SPFA() 19 { 20 memset(visited,false,sizeof(visited)); 21 for(int i=1;i<maxn;i++) 22 dist[i]=INF; 23 24 //起初我把与0临近的城市的dist[]值也赋成了0 25 //这样做是错误的 26 //因为如果与0临近的城市的dist[]值为0,那么0就不会松弛与其相邻的边,直接跳出循环 27 dist[0]=0; 28 queue<int >que; 29 while(!que.empty()) 30 que.pop(); 31 que.push(0); 32 33 while(!que.empty()) 34 { 35 int u=que.front(); 36 que.pop(); 37 visited[u]=false; 38 39 for(map<int ,int >::iterator it=mymap[u].begin();it != mymap[u].end();++it) 40 { 41 int v=it->first; 42 int weight=it->second; 43 if(dist[v] > dist[u]+weight) 44 { 45 dist[v]=dist[u]+weight; 46 if(!visited[v]) 47 { 48 que.push(v); 49 visited[v]=true; 50 } 51 } 52 } 53 } 54 } 55 56 int main() 57 { 58 while(~scanf("%d%d%d",&T,&S,&D)) 59 { 60 mymap.clear(); 61 for(int i=1;i<=T;i++) 62 { 63 int a,b,time; 64 scanf("%d%d%d",&a,&b,&time); 65 if(!mymap[a].count(b)) 66 { 67 mymap[a][b]=time; 68 mymap[b][a]=time; 69 } 70 else 71 { 72 mymap[a][b]=(mymap[a][b] > time ? time:mymap[a][b]); 73 mymap[b][a]=(mymap[b][a] > time ? time:mymap[b][a]); 74 } 75 } 76 for(int i=1;i<=S;i++) 77 { 78 scanf("%d",nex+i); 79 mymap[0][nex[i]]=0; 80 } 81 for(int i=1;i<=D;i++) 82 scanf("%d",want+i); 83 SPFA(); 84 int ans=dist[want[1]]; 85 for(int i=2;i<=D;i++) 86 ans=(dist[want[i]] < ans ? dist[want[i]]:ans); 87 printf("%d ",ans); 88 } 89 return 0; 90 }