Description
Background 
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight. 
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.

Problem 
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4 题意:这个题目呢,跟上一篇的题意有点相反,这一次是求在街道1到达街道n的路径所能承受的最大重量。也就是求能从1到达n的路径上的最小承重的最大值。
思路:Dijkstra运用,我们知道dijkstra是每一次将离源点最近的那一一个点进行松弛,而我们现在要求最小承重的最大值,那我们就应该将离源点承重最大的那个点进行松弛。
 #include<iostream>
#include<algorithm>
#include<cstring> using namespace std;
int n, m, dis[], mp[][], vis[];
void Dijkstra()
{
for (int i = ; i <= n; i++) {
vis[i] = ; dis[i] = mp[][i];//初始化为1到i的最大承重
}
for (int i = ; i <= n; i++) {
int cnt = , k;
for (int j = ; j <= n; j++) {
if (!vis[j] && dis[j] > cnt) {
cnt = dis[j];
k = j;
}
}
vis[k] = ;
for (int j = ; j <= n; j++) {
if (!vis[j] && dis[j] < min(dis[k], mp[k][j]))
dis[j] = min(dis[k], mp[k][j]);
}
}
}
int main()
{
ios::sync_with_stdio(false);
int T;
cin >> T;
for(int t=;t<=T;t++){
cin >> n >> m;
memset(mp, , sizeof(mp));
for (int a, b, c, i = ; i < m; i++) {
cin >> a >> b >> c;
mp[a][b] = mp[b][a] = c;
}
Dijkstra();
cout << "Scenario #" << t << ":" << endl;
cout << dis[n] << endl << endl;
}
return ;
}

POJ 1797 Heavy Transportation(Dijkstra运用)的更多相关文章

  1. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  2. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  3. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  4. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  5. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  6. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  7. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  8. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  9. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

  10. POJ 1797 Heavy Transportation (最大生成树)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

随机推荐

  1. linux类库之log4j-LogBack-slf4j-commons-logging

    log4j http://commons.apache.org/proper/commons-logging/ http://logging.apache.org/log4j/2.x/ The Com ...

  2. sas信用评分之第二步变量筛选

    sas信用评分之第二步变量筛选 今天介绍变量初步选择.这部分的内容我就只介绍information –value,我这次做的模型用的逻辑回归,后面会更新以基尼系数或者信息熵基础的筛选变量,期待我把. ...

  3. codevs1506 传话

    题目描述 Description 一个朋友网络,如果a认识b,那么如果a第一次收到某个消息,那么会把这个消息传给b,以及所有a认识的人. 如果a认识b,b不一定认识a. 所有人从1到n编号,给出所有“ ...

  4. Servlet工作流程

    1.加载Servlet类 类加载器负责加载servlet类. 当Web容器接收到servlet的第一个请求时,将加载servlet类. 2.创建Servlet实例 Web容器在加载servlet类之后 ...

  5. hdu 2844 混合背包【背包dp】

    http://acm.hdu.edu.cn/showproblem.php?pid=2844 题意:有n种纸币面额(a1,a2,...an),每种面额对应有(c1,c2,...cn)张.问这些钱能拼成 ...

  6. jQuery $.isNumeric vs. $.isNaN vs. isNaN

    在jQuery中,有几种方式可以判断一个对象是否是数字,或者可否转换为数字. 首先,jQuery.isNaN()在最新版本中已经被移除了(1.7之后),取而代之的是  jQuery.isNumeric ...

  7. ffmpeg在iOS的使用 - iFrameExtractor源码解析

    http://www.cocoachina.com/ios/20150914/13284.html iFrameExtractor地址:https://github.com/lajos/iFrameE ...

  8. 【转载】使用 gnuplot 在网页中显示数据

    来源:http://www.ibm.com/developerworks/cn/aix/library/au-gnuplot/ 简介 gnuplot 是一个用于生成趋势图和其他图形的工具.它通常用于收 ...

  9. 关于Spring+mybatis+PageHelper分页插件PageHelper的使用策略

    把插件jar包导入项目(具体上篇有介绍http://blog.csdn.net/qq_33624284/article/details/72821811) spring-mybatis.xml文件中配 ...

  10. XAML 特效

    <Window x:Class="WpfApp5.MainWindow" xmlns="http://schemas.microsoft.com/winfx/200 ...