PoJ(2263),Floyd,最小值中的最大值

题目链接:http://poj.org/problem?id=2263

题意:题中给出相连通不同城市之间的载货量,要求找到一条从指定起点到终点的路径,并满足载货量最大。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int POINT = ; int dis[POINT][POINT];
string city[POINT];
int main()
{
int cases = ;
int n,r;
while(scanf("%d %d",&n,&r),n||r)
{
cases++;
memset(dis,,sizeof(dis));
int numcity = ;
for(int i=; i<=r; i++)
{
string a,b;
int w;
cin>>a>>b>>w;
int u=,v=;
for(int j=; j<=numcity; j++)
{
if(a==city[j])
u = j;
if(b==city[j])
v = j;
}
if(u==)
{
u = numcity;
city[numcity++] = a;
}
if(v==)
{
v = numcity;
city[numcity++] = b;
}
dis[u][v] = dis[v][u] = w;
} for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
dis[i][j] = max(dis[i][j],min(dis[i][k],dis[k][j]));
}
} string a,b;
cin>>a>>b;
int u,v;
for(int i=; i<=n; i++)
{
if(a == city[i])
u = i;
if(b == city[i])
v = i;
}
printf("Scenario #%d\n%d tons\n\n",cases,dis[u][v]);
for(int i=;i<=n;i++)
city[i].clear();
}
}
上一篇:计算 sql查询语句所花时间


下一篇:安装XMind