标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 29572 Accepted Submission(s): 10160
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 #include <queue> 6 using namespace std; 7 const int maxn = 1005; 8 const int INF = 0x3f3f3f3f; 9 int d[maxn][maxn]; 10 int n,m; 11 int s[maxn],c[maxn]; 12 void floyd(){ 13 for(int k = 1; k<=maxn; k++) 14 for(int i = 1; i<=maxn; i++) 15 if(d[i][k]!=INF) 16 for(int j = 1; j<=maxn; j++) 17 d[i][j] = min(d[i][j],d[i][k] + d[k][j]); 18 } 19 void solve(){ 20 int t,S,D; 21 while(scanf("%d%d%d",&t,&S,&D)!=EOF){ 22 memset(d,INF,sizeof(d)); 23 for(int i = 0; i<t; i++){ 24 int a,b,time; 25 scanf("%d%d%d",&a,&b,&time); 26 if(d[a][b]>time) 27 d[a][b] = time,d[b][a] = time; 28 } 29 floyd(); 30 for(int i = 0; i<S; i++) scanf("%d",&s[i]); 31 for(int j = 0; j<D; j++) scanf("%d",&c[j]); 32 int ans = INF; 33 for(int i = 0; i<S; i++) 34 for(int j = 0; j<D; j++) 35 ans = min(ans,d[s[i]][c[j]]); 36 printf("%d\n",ans); 37 } 38 } 39 int main() 40 { 41 solve(); 42 return 0; 43 }
标签:
原文地址:http://www.cnblogs.com/littlepear/p/5463950.html