标签:class blog code 2014 string os
求给定起点到终点的路径中,最小边权的最大值
#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #define inf 0x3f3f3f3f #define ll __int64 #define mod 1000000007 using namespace std; char s1[35],s2[25],city[210][35]; int mp[210][210],n,r; void floyd() { for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) mp[i][j]=max(mp[i][j],min(mp[i][k],mp[k][j])); } int main() { int t,a,b,d,cnt,i,j; t=1; while(scanf("%d%d",&n,&r)&&(n||r)) { cnt=1; memset(mp,0,sizeof mp); for(i=1;i<=r;i++) { scanf("%s%s %d",s1,s2,&d); a=b=0; for(j=1;j<cnt;j++) { if(strcmp(s1,city[j])==0) a=j; if(strcmp(s2,city[j])==0) b=j; } if(!a) { strcpy(city[cnt],s1); a=cnt; cnt++; } if(!b) { strcpy(city[cnt],s2); b=cnt; cnt++; } mp[a][b]=mp[b][a]=d; } scanf("%s%s",s1,s2); floyd(); for(j=1;j<=n;j++) { if(strcmp(s1,city[j])==0) a=j; if(strcmp(s2,city[j])==0) b=j; } printf("Scenario #%d\n%d tons\n\n",t++,mp[a][b]); } return 0; }
poj2263 Heavy Cargo --- floyd求最大容量路,布布扣,bubuko.com
poj2263 Heavy Cargo --- floyd求最大容量路
标签:class blog code 2014 string os
原文地址:http://blog.csdn.net/u011032846/article/details/34930281