poj pku2263floyd

水题,不解释

View Code
#include<stdio.h>
#include
<string.h>
const int INF = 9999999;
int n,r,map[250][250];
char city[250][30];
int num;
int max(int a,int b){
return a>b?a:b;
}
int min(int a,int b){
return a<b?a:b;
}
int find(char s[]){
int i;
for(i=0;i<num;i++)
if(strcmp(city[i],s)==0)
return i;
strcpy(city[i],s);
num
++;
return i;
}
int main()
{
char s[30],t[30];
int i,j,k,cases=1,w;
while(scanf("%d%d",&n,&r)!=EOF)
{
if(n==0&&r==0) break;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(i==j) map[i][j]=INF;
else map[i][j]=0;
}
num
=0;
for(i=0;i<r;i++)
{
scanf(
"%s%s%d",s,t,&w);
int x=find(s);
int y=find(t);
map[x][y]
=map[y][x]=w;
}
for(k=0;k<n;k++)
for(i=0;i<n;i++)
for(j=0;j<n;j++)
map[i][j]
=max(map[i][j],min(map[i][k],map[k][j]));
scanf(
"%s%s",s,t);
i
=find(s);
j
=find(t);
printf(
"Scenario #%d\n",cases++);
printf(
"%d tons\n\n",map[i][j]);

}
return 0;
}

  

posted @ 2011-09-14 14:48  Because Of You  Views(141)  Comments(0Edit  收藏  举报