Description

Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only 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

The input will contain one or more test cases. The first line of each test case will contain two integers: the number of cities n (2<=n<=200) and the number of road segments r (1<=r<=19900) making up the street network. 
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

For each test case, print three lines:

  • 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 题目意思:有n个城市,m条连接两个城市的道路,每条道路有自己的最大复载量。现在问从城市a到城市b,车上的最大载重能为多少。 解题思路:这里并不是求解最短路径,而是要求通行能力(可称为容量)最大的路,这种路可以成为最大容量路,可以用Floyd算法求最短路径的思想求解。
 w[i][j]=max(w[i][j],min(w[i][k],w[k][j]))
这里需要好好的思考一下,对于点i和点j,中间点的加入更改的递推式应该取最大值,因为求的就是最大的容量值,而对于新加进来的i-k和k-j必须取小的值,因为小的值才是这条路的容量值,
三重循环遍历之后就求出了每两点之间的最大容量值。注意初始化的时候w应该都为0,因为求的是最大值。
 #include<cstring>
#include<cstdio>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int w[][];
char start[];
char dest[];
int n,m;
int num;
char city[][];///城市名
void Floyd()
{
int i,j,k;
for(k=; k<n; k++)
{
for(i=; i<n; i++)
{
for(j=; j<n; j++)
{
w[i][j]=max(w[i][j],min(w[i][k],w[k][j]));
}
}
}
}
int index(char *s)///给城市分配编号
{
int i;
for(i=; i<num; i++)
{
if(!strcmp(city[i],s))
{
return i;
}
}
strcpy(city[i],s);
num++;
return i;
}
int main()
{
int i,j,limit;
int counts;
int a,b;
counts=;
while(scanf("%d%d",&n,&m)!=EOF)
{
getchar();
if(n==)
{
break;
}
for(i=; i<n; i++)///初始化邻接表
{
for(j=; j<n; j++)
{
w[i][j]=;
}
}
for(i=; i<n; i++)
{
w[i][i]=INF;
}
num=;
for(i=; i<m; i++)
{
scanf("%s%s%d",start,dest,&limit);
getchar();
a=index(start);
b=index(dest);
w[a][b]=w[b][a]=limit;///双向
}
Floyd();
scanf("%s%s",start,dest);///读入起点城市和终点城市
a=index(start);
b=index(dest);
printf("Scenario #%d\n",counts++);
printf("%d tons\n",w[a][b]);
printf("\n");
}
return ;
}

 

Heavy Cargo POJ 2263 (Floyd传递闭包)的更多相关文章

  1. POJ 3275 Floyd传递闭包

    题意:Farmer John想按照奶牛产奶的能力给她们排序.现在已知有N头奶牛(1 ≤ N ≤ 1,000).FJ通过比较,已经知道了M(1 ≤ M ≤ 10,000)对相对关系.每一对关系表示为&q ...

  2. POJ 3660 Floyd传递闭包

    题意:牛有强弱,给出一些牛的强弱的胜负关系,问可以确定几头牛的排名. 思路: Floyd传递闭包 // by SiriusRen #include <bitset> #include &l ...

  3. Cow Contest POJ - 3660 floyd传递闭包

    #include<iostream> #include<cstring> using namespace std; ,INF=0x3f3f3f3f; int f[N][N]; ...

  4. POJ 2263 Heavy Cargo(Floyd + map)

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3768   Accepted: 2013 Descr ...

  5. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

  6. POJ 3660—— Cow Contest——————【Floyd传递闭包】

    Cow Contest Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit  ...

  7. POJ 3660 Cow ContestCow(Floyd传递闭包)题解

    题意:给出m个关系,问你能确定机头牛的排名 思路:要确定排名那必须要把他和其他n-1头牛比过才行,所以Floyd传递闭包,如果赢的+输的有n-1就能确定排名. 代码: #include<cstd ...

  8. POJ2263 Heavy Cargo

    Heavy Cargo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4004   Accepted: 2124 Descr ...

  9. POJ3660:Cow Contest(Floyd传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16941   Accepted: 9447 题目链接 ...

随机推荐

  1. javascript 中x++和++x的不同

    x++和++x都是给x加一,但是前者是完成赋值之后再递增x,后者相反. 例如:如果x是5,y=x++会将y设置为5,x设置为6:而y=++x会将x和y都设置为6.

  2. jquery里遍历普通数组和多维数组的方法及实例

    jquery里遍历数组用的是$.each,下面站长给大家几个具体的实例: 实例1.遍历一个普通的一维数组: 1 2 3 4 5 6 7 8 <script> //声明数据有下面两种方式 / ...

  3. 百度云虚拟主机BCH安装PHP框架CodeIgniter

    百度云虚拟主机BCH官方未支持CodeIgniter框架,本人参加php中文网活动获取一百度云虚拟主机,本人选的ThinkPHP版,但本人喜欢CodeIgniter框架,因此尝试在该主机上配置Code ...

  4. 我的 Delphi 学习之路 —— Delphi 助手的安装

    标题:我的 Delphi 学习之路 -- Delphi 助手的安装 作者:断桥烟雨旧人伤 Delphi 助手的安装 CnWizards 类似于 VS 中的番茄助手,在编写 Delphi 代码时帮助极大 ...

  5. 3.Hadoop测试Yarn和MapReduce

    Hadoop测试Yarn和MapReduce 1.配置Yarn (1)配置ResourceManager 生产环境中,一般是重开一台机器作为ResourceManager,这里我们以Master机器代 ...

  6. 话说文件系统——VFS简介(二)

    linux可以与很多文件系统完美的结合,可以很容易地把Windows.其他Unix系统.甚至在市场上很小众的文件系统轻松地移植到linux中. 这对于linux今天的成功是功不可没的,那为什么这么厉害 ...

  7. 11-while循环基本使用

    hm_02_第一个while循环.py def main(): i = 1 while i <= 3: print(i, 'Hello world') i += 1 print(i) 1 Hel ...

  8. python教程(三)·函数进阶(下)

    下半部分果然很快到来,这次介绍函数的更高级用法,装饰器! 函数嵌套 先来说说函数嵌套,python中的函数是可以嵌套的,也就是说可以将一个函数放在另一个函数里面,比如: >>> de ...

  9. A1037

    给两个序列,一一对应相乘,求最大和. 0不算数,输入时按正负共分为4个数组. #include<cstdio> #include<algorithm> #include< ...

  10. linux中配置JDK环境变量

    使用的centos版本为 7.5 首先我们要把jdk拷到linux中,这里我们借助XShell工具,我们先来看看Xshell的用法 打开Xshell 后点击文件,“新建“,如下图: 起一个名称,主机填 ...