来源poj2263

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的最大的载重,似乎之前做过,只要用dijkstar变形一下,每次找最大的来搜,收到end就是最大的了

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
//#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+10;
char name[205][35];
int map[205][205];
int visit[205];
int value[205];
int find(int n,char b[35])
{
rep(i,0,n)
{
if(strcmp(b,name[i])==0)
return i;
}
return -1;
}
int dijkstra(int n,int star,int end)
{
int pos,MAX=0;
value[star]=inf;
rep(i,0,n)
{
if(map[star][i]!=-1)
value[i]=map[star][i];
if(MAX<value[i]&&i!=star)
{
MAX=value[i];
pos=i;
}
}
visit[star]=1;
visit[pos]=1;
if(pos==end) return MAX;
rep(i,1,n)
{
MAX=0;
rep(j,0,n)
{
if(map[pos][j]!=-1&&visit[j]==0)
{
if(value[j]==-1) value[j]=min(map[pos][j],value[pos]);
else value[j]=max(value[j],min(map[pos][j],value[pos]));
}
}
rep(j,0,n)
{
if(MAX<value[j]&&j!=star&&visit[j]==0)
{
pos=j;
MAX=value[j];
}
}
visit[pos]=1;
if(pos==end) return value[end];
}
return value[end];
}
int main()
{
int n,m,k;
int bits=1;
char a[35],b[35];
while(~scff(n,m)&&n)
{
mm(visit,0);
mm(value,-1);
mm(map,-1);
int cas=0;
while(m--)
{
sf("%s%s%d",a,b,&k);
int x,y;
x=find(cas,a);
if(x==-1)
{
x=cas;
strcpy(name[cas++],a);
}
y=find(cas,b);
if(y==-1)
{
y=cas;
strcpy(name[cas++],b);
}
map[x][y]=map[y][x]=k;
}
sf("%s%s",a,b);
int star,end;
star=find(cas,a);end=find(cas,b);
int ans=dijkstra(n,star,end);
pf("Scenario #%d\n%d tons\n\n",bits++,ans);
}
return 0;
}

K - Heavy Cargo dijkstar的更多相关文章

  1. POJ2263 Heavy Cargo

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

  2. POJ 2263 Heavy Cargo(Floyd + map)

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

  3. Heavy Cargo POJ 2263 (Floyd传递闭包)

    Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...

  4. poj2263 zoj1952 Heavy Cargo(floyd||spfa)

    这道题数据范围小,方法比较多.我用floyd和spfa分别写了一下,spfa明显有时间优势. 一个小技巧在于:把城市名称对应到数字序号,处理是用数字. 方法一:spfa #include<ios ...

  5. POJ 2263 Heavy Cargo 多种解法

    好题.这题可以有三种解法:1.Dijkstra   2.优先队列   3.并查集 我这里是优先队列的实现,以后有时间再用另两种方法做做..方法就是每次都选当前节点所连的权值最大的边,然后BFS搜索. ...

  6. POJ 2263 Heavy Cargo(ZOJ 1952)

    最短路变形或最大生成树变形. 问 目标两地之间能通过的小重量. 用最短路把初始赋为INF.其它为0.然后找 dis[v]=min(dis[u], d); 生成树就是把最大生成树找出来.直到出发和终点能 ...

  7. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  8. poj1013

    题目大意:假造的银币 Sally Jones有一些游客给的银币,但是只有11枚是真正的银币(有一枚是假的),从颜色和大小是无法区分真比还是假币的,但是它的重量和真币是不同的,Sally Jones它是 ...

  9. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

随机推荐

  1. jquery 多级联动下拉列表含(数据模型)

    方法 /** * 级联 * 联动 * @param url:访问json数据的地址 * @param param:参数 * @param levelIds:页面下拉标签数组,为联动级数 * @priv ...

  2. [Python设计模式] 第20章 挨个买票——迭代器模式

    github地址:https://github.com/cheesezh/python_design_patterns 迭代器模式 迭代器模式,提供一种方法顺序访问一个聚合对象中各个元素,而又不暴露该 ...

  3. 关于关键字 volatile

    关于 volatile 的使用,也是 C 语言面试的月经问题.标准答案来了: volatile is a qualifier that is applied to a variable when it ...

  4. 再看C# ThreadPool与Task的认识总结

    工作线程与I/O线程     在ThreadPool中有这样一个方法: public static bool SetMaxThreads(int workerThreads, int completi ...

  5. 解析 .Net Core 注入——注册服务

    在学习 Asp.Net Core 的过程中,注入可以说是无处不在,对于 .Net Core 来说,它是独立的一个程序集,没有复杂的依赖项和配置文件,所以对于学习 Asp.Net Core 源码的朋友来 ...

  6. webstorm11.0下载地址和webstorm11.0破解程序patcher.exe下载使用方法说明 前端IDE工具的利器

    20160107以下亲测可行. webstorm11.0下载地址:http://www.fxxz.com/soft/109234.html webstorm11.0下载安装破解使用说明: 下载完Web ...

  7. springboot整合三 共享session,集成springsession

    官网介绍 - spring:session:https://docs.spring.io/spring-session/docs/current/reference/html5/ 1. Mave依赖 ...

  8. 星云STS 常用配置

    STS4  下载地址:https://spring.io/tools    (这个版本没有tomcat插件) STS3  下载地址:https://spring.io/tools3/sts/all ( ...

  9. Jquery Post提交时Content-Type的不同取值详解

    四种常见的 POST 提交数据方式 我们知道,HTTP 协议是以 ASCII 码传输,建立在 TCP/IP 协议之上的应用层规范.规范把 HTTP 请求分为三个部分:状态行.请求头.消息主体.类似于下 ...

  10. 用VSCode写Vue要用到的配置

    [本文出自天外归云的博客园] 文件-首选项-设置-打开settings.json-用户设置区域填写: { "workbench.colorTheme": "Monokai ...