标签:
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int Max_v = 1000 + 10; const int INF = 9999999; int cost[Max_v][Max_v];//权值 int d[Max_v];//顶点s出发最短距离 bool used[Max_v];//以使用过的图 int V;//顶点数 int Edge;//边数 int T,S,D; void dijkstra(int s) { fill(d,d+V+1,INF); fill(used,used+V+1,false); d[s] = 0; while(true) { int v = -1; for(int u = 1; u<= V; u++) { if(!used[u] && (v == -1 || d[u] < d[v])) v = u; } if(v == -1) break; used[v] = true; for(int u = 1; u <= V; u++) { d[u] = min(d[u],d[v] + cost[v][u]); } } } int start[Max_v]; int want[Max_v]; int main() { #ifdef xxz freopen("in.txt","r",stdin); #endif // xxz int a,b,c; while(~scanf("%d%d%d",&T,&S,&D)) { for(int i = 0; i < Max_v; i++) fill(cost[i],cost[i]+Max_v,INF); V = 0; for(int i = 0; i < T; i++) { scanf("%d%d%d",&a,&b,&c); V = max(max(a,b),V); cost[a][b] = cost[b][a]= min(cost[a][b],c); } for(int i = 0;i < S; i++) scanf("%d",&start[i]); for(int i = 0; i < D; i++) scanf("%d",&want[i]); int ans = INF; for(int i = 0; i< S; i++) { dijkstra(start[i]); for(int j = 0; j < D; j++) { ans = min(ans,d[want[j]]); } } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/u013445530/article/details/44204765