标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23416 Accepted Submission(s): 8154
1 #include<stdio.h> 2 #define INF 0xffff 3 #define MIN(x,y) x<y?x:y 4 #define MAX(x,y) x>y?x:y 5 typedef struct{ 6 int begin,end,time; 7 }node; 8 int city[1001][1001],start[10010],final[10010]; 9 node deta[10010]; 10 int main(){//printf("%d\n",INF); 11 int T,S,D,min,max,t; 12 while(~scanf("%d%d%d",&T,&S,&D)){ 13 for(int i=1;i<=1000;++i){ 14 for(int j=1;j<=1000;++j){ 15 city[i][j]=city[j][i]=INF; 16 } 17 } 18 for(int i=0;i<T;++i){ 19 scanf("%d%d%d",&deta[i].begin,&deta[i].end,&deta[i].time); 20 city[deta[i].end][deta[i].begin]=city[deta[i].begin][deta[i].end]=deta[i].time; 21 if(!i)min=MIN(deta[i].begin,deta[i].end),max=MAX(deta[i].begin,deta[i].end); 22 else min=MIN(min,deta[i].begin),min=MIN(min,deta[i].end),max=MAX(max,deta[i].begin),max=MAX(max,deta[i].end); 23 } 24 for(int i=0;i<S;++i){ 25 scanf("%d",&start[i]); 26 } 27 for(int i=0;i<D;++i)scanf("%d",&final[i]); 28 for(int i=min;i<=max;++i){ 29 for(int j=min;j<=max;++j){ 30 for(int k=min;k<=max;++k){ 31 city[j][k]=city[j][i]+city[i][k]<city[j][k]?city[j][i]+city[i][k]:city[j][k]; 32 } 33 } 34 } 35 for(int i=0;i<S;++i){ 36 for(int j=0;j<D;++j){ 37 if(!i&&!j)t=city[start[i]][final[j]]; 38 t=MIN(t,city[start[i]][final[j]]); 39 } 40 } 41 printf("%d\n",t); 42 } 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4671095.html