佛洛依德变形
代码:
#include<iostream>
#include<map>
#include<cstring>
#include<cstdio>
#include<string>
#define maxn 205
#define INF 10000000
using namespace std;
int weight[maxn][maxn];
int main()
{
int n,m;
int cas=0;
while(scanf("%d%d",&n,&m),n+m){
cas++;
int tot=0,temp;
int a,b;
string s1,s2;
map<string,int> ms;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
weight[i][j]=0;
for(int i=0;i<n;++i) weight[i][i]=INF;
for(int i=0;i<m;++i){
cin>>s1>>s2>>temp;
if(ms.find(s1)==ms.end()) ms[s1]=tot++;
if(ms.find(s2)==ms.end()) ms[s2]=tot++;
weight[ms[s1]][ms[s2]]=weight[ms[s2]][ms[s1]]=temp;
}
for(int k=0;k<n;++k)
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
weight[i][j]=max(weight[i][j],min(weight[i][k],weight[k][j]));
cin>>s1>>s2;
printf("Scenario #%d\n",cas);
printf("%d tons\n",weight[ms[s1]][ms[s2]]);
}
return 0;
}