标签:mem find div scanf others search mod rip amp
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4468 Accepted Submission(s):
1798
1 #include "bits/stdc++.h" 2 #define mem(a,b) memset(a,b,sizeof(a)) 3 using namespace std; 4 typedef long long LL; 5 const int MAX=105; 6 const int oo=100000000; 7 int ans; 8 int n,m; 9 int dist[MAX][MAX],a[MAX][MAX]; 10 inline int mn(int x,int y){return x<y?x:y;} 11 void floyd(){ 12 ans=oo; 13 int i,j,k; 14 for (k=1;k<=n;k++){ 15 for (i=1;i<k;i++){ 16 for (j=i+1;j<k;j++){ 17 ans=mn(ans,a[i][k]+a[k][j]+dist[i][j]); 18 } 19 } 20 for (i=1;i<=n;i++){ 21 for (j=1;j<=n;j++){ 22 dist[i][j]=mn(dist[i][j],dist[i][k]+dist[k][j]); 23 } 24 } 25 } 26 } 27 int main(){ 28 freopen ("find.in","r",stdin); 29 freopen ("find.out","w",stdout); 30 int i,j; 31 int u,v,w; 32 while (~scanf("%d%d",&n,&m)){ 33 for (i=1;i<=n;i++) for (j=1;j<=n;j++) dist[i][j]=a[i][j]=(i==j?0:oo); 34 for (i=1;i<=m;i++){ 35 scanf("%d%d%d",&u,&v,&w); 36 if (w<a[u][v]) 37 a[u][v]=a[v][u]=dist[u][v]=dist[v][u]=w; 38 } 39 floyd(); 40 if (ans>=oo) 41 puts("It‘s impossible."); 42 else printf("%d\n",ans); 43 } 44 return 0; 45 }
HDU-1599 find the mincost route(floyd求最小环)
标签:mem find div scanf others search mod rip amp
原文地址:http://www.cnblogs.com/keximeiruguo/p/6055289.html