Description
limited by the weight restrictions that apply for the roads along the path you want to drive.
Given start and destination city, your job is to determine the maximum load of the Godzilla V12 so that there still exists a path between the two specified cities.
Input
Then r lines will follow, each one describing one road segment by naming the two cities connected by the segment and giving the weight limit for trucks that use this segment. Names are not longer than 30 characters and do not contain white-space characters.
Weight limits are integers in the range 0 - 10000. Roads can always be travelled in both directions.
The last line of the test case contains two city names: start and destination.
Input will be terminated by two values of 0 for n and r.
Output
- a line saying "Scenario #x" where x is the number of the test case
- a line saying "y tons" where y is the maximum possible load
- a blank line
Sample Input
4 3 Karlsruhe Stuttgart 100 Stuttgart Ulm 80 Ulm Muenchen 120 Karlsruhe Muenchen 5 5 Karlsruhe Stuttgart 100 Stuttgart Ulm 80 Ulm Muenchen 120 Karlsruhe Hamburg 220 Hamburg Muenchen 170 Muenchen Karlsruhe 0 0
Sample Output
Scenario #1 80 tons Scenario #2 170 tons
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
const int inf=(1<<28);
map<string,int>q;
int tq;
char str1[1000],str2[1000];
int a[300][300];
int n,e;
int main()
{
int pl=1;
while(scanf("%d%d",&n,&e)==2&&n)
{
q.clear();tq=0;
memset(a,0,sizeof(a));
for(int i=0;i<e;i++)
{
int w;
scanf("%s%s%d",str1,str2,&w);
if(q[str1]==0) q[str1]=++tq;
if(q[str2]==0) q[str2]=++tq;
a[q[str1]][q[str2]]=a[q[str2]][q[str1]]=w;
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
a[i][j]=max(a[i][j],min(a[i][k],a[k][j]));
}
}
}
scanf("%s%s",str1,str2);
printf("Scenario #%d\n%d tons\n\n",pl++,a[q[str1]][q[str2]]);
}
return 0;
}