POJ 1797 Heavy Transportation(Dijkstra运用)
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
Output
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运用)的更多相关文章
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
- POJ 1797 Heavy Transportation (最大生成树)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
随机推荐
- java通过实体类组装报文
条件: 1.实体类字段名 首字母小写(java规范),再通过报文的需求,填充的时候做对应修改即可(正常报文首字母是大写的)! 2.假如xml标签首字母是小写,那么实体类就给大写,首字母是大写,那么实体 ...
- 在 Linux 启动或重启时执行命令与脚本
有时可能会需要在重启时或者每次系统启动时运行某些命令或者脚本.我们要怎样做呢?本文中我们就对此进行讨论. 我们会用两种方法来描述如何在 CentOS/RHEL 以及 Ubuntu 系统上做到重启或者系 ...
- DDoS攻击新趋势:海量移动设备成为新一代肉鸡
近期,阿里云安全团队观察到数十起大规模的应用层资源耗尽式DDoS攻击(应用层CC攻击).阿里云DDoS高防实现智能防护全程自动化检测并清洗,未对用户侧业务产生任何影响,这类攻击存在一些共同的特征,阿里 ...
- tf.cast用法
tf.cast:用于改变某个张量的数据类型 例如: import tensorflow as tf;import numpy as np; A = tf.convert_to_tensor(np.ar ...
- Notepad++颜色配置
目前看着比较顺眼的notepad++配置,记录如下:
- Mysql统计信息处理及binlog解释
TODO use db_name; -- 分析表 ANALYZE TABLE table_name; -- 查看表信息 ; -- 查看索引 SHOW INDEX FROM table_name; ht ...
- day1-初识Python之变量
1.python安装与环境配置 1.1.Windows下的python解释器安装 打开官网 https://www.python.org/downloads/windows/ 下载中心 测试安装是否成 ...
- AtCoder Beginner Contest 077 C Snuke Festival(二分)
二分水题,A,B,C三个数组排序,对于每个B[i],二分算出来有多少A比他小,多少C比他大,然后扫一遍出结果.O(nlog(n))水过. #include <bits/stdc++.h> ...
- H3C 路由器的特点
- WebStorm使用参考手册
WebStorm 是 JetBrains 推出的一款商业的 JavaScript 开发工具 任何一个编辑器都需要保存(ctrl + s),这是所有win平台上编辑类软件的特点,但是webstorm编辑 ...