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. bat脚本实现复制特定后缀文件到其他目录

    @echo off for /r %%a in (*.txt) do copy %%a D:\1 pause 1.for /r主要用于搜索指定路径及其所有子目录中符合要求的文件(/r后如果没有指定目录 ...

  2. 在js内生成PDF文件并下载的功能实现(不调用后端),以及生成pdf时换行的格式不被渲染,word-break:break-all

    在js内生成PDF文件并下载的功能实现(不调用后端),以及生成pdf时换行的格式不被渲染,word-break:break-all 前天来了个新需求, 有一个授权书的文件要点击下载, 需要在前端生成, ...

  3. Fiddler无所不能——之测试开发攻城狮必备利器

    Fiddler无所不能——之测试开发攻城狮必备利器 1.模拟真实网络环境4g网.3g网络.2g网络.弱网.请求超时 开启弱网Rules——Performance——勾选Simulate Modem S ...

  4. 20155220 2016-2017-2 《Java程序设计》第八周学习总结

    20155220 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 第14章 NIO与NIO2 NIO简介 NIO使用频道来衔接数据结点,在处理数据时,NIO可 ...

  5. 20155319 《Java程序设计》实验五(网络编程与安全)实验报告

    20155319 <Java程序设计>实验五(网络编程与安全)实验报告 一.实验内容及步骤 (一) 两人一组结对编程 参考http://www.cnblogs.com/rocedu/p/6 ...

  6. 20155322 2016-2017-2 《Java程序设计》第2周学习总结

    20155322 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 本周按照教学安排学习教材的第三章,下面简单的概括一下我的学习总结: 第三章的主要内容是有关于 ...

  7. 【MongoDB】如何注册windows服务

    一.为什么要注册windows服务 mongodb启动比较麻烦,每次都要cmd去开启.注册windows服务,可以设置开机启动,比较友好. 二.如何注册windows服务 1.安装mongodb 2. ...

  8. python 多线程笔记(3)-- 线程的私有命名空间

    线程的私有命名空间实现: threading_namespace = threading.local() import threading import time import random thre ...

  9. [NOIp2018]铺设道路 贪心

    LG传送门 考场上写的\(O(nlogn)\)做法,具体思想是把深度从低到高排个序,开一个标记数组,每次加入的时候标记当前位置并判断:如果当前加入的位置两边都被标记过,则下次的贡献-1,若两边都没有被 ...

  10. NB-IOT模组指令AT+NMSTATUS和AT+CGPADDR对比

    1. AT+NMSTATUS,这个指令是用来查询模块在IOT平台的注册情况.注册指的是lwm2m协议里面的注册机制,详细可以参考lwm2m协议. 2. AT+MREGSWT,设置重启之后,自动启动注册 ...