//求从起点到终点最大运输量
//运输量取决于单条路径的最大容量
//用floyd算法,动规
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
#define MAXN 201
#define INF 1000000
map<string,int> city;
int weight[MAXN][MAXN];
int Edge[MAXN][MAXN];
int T;
int n,r;
int citynumber;
int queryCity(string str)
{
map<string,int>::iterator iter;
iter = city.find(str);
if(iter != city.end())
{
return iter->second;
}
else
{
city[str] = citynumber;
citynumber++;
return city[str];
}
}
void Floyd()
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
weight[i][j] = Edge[i][j];
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
for(int k = 1; k <= n; k++)
{
weight[i][j] = max(weight[i][j],min(weight[i][k],weight[k][j]));
}
}
}
}
int main()
{
T = 0;
while(cin>>n>>r)
{
if(n == 0 && r == 0)
break;
citynumber = 1;
T++;
for(int i = 0; i <= n; i++)
{
Edge[i][i] = INF;
for(int j = 0; j <= n; j++)
{
if(i != j)
Edge[i][j] = 0;
}
}
for(int i = 0; i < r; i++)
{
string ca,cb;
int ton;
cin>>ca>>cb>>ton;
int x = queryCity(ca);
int y = queryCity(cb);
Edge[x][y] = ton;
Edge[y][x] = ton;
}
Floyd();
string cs,ce;
cin>>cs>>ce;
int st = queryCity(cs);
int en = queryCity(ce);
cout<<"Scenario #"<<T<<endl;
cout<<weight[st][en]<<" tons"<<endl;
}
return 0;
}
poj 2263 重型运输
最新推荐文章于 2022-10-10 10:23:51 发布