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 ...
随机推荐
- quarts之Cron表达式示例
cron表达式含义及范例如下: 字段名 允许的值 允许的特殊字符 秒 0- ...
- 【JZOJ4876】【NOIP2016提高A组集训第10场11.8】基因突变
题目描述 邪恶的707刚刚从白垩纪穿越回来,心中产生了一个念头:我要统治人类! 但是统治人类是很庞大且复杂的一个工程,707尝试了洗脑,催眠,以及武装镇压都没能成功地统治人类,于是她决定从科学上对人类 ...
- Person Re-identification 系列论文笔记(五):SVD-net
SVDNet for Pedestrian Retrieval Sun Y, Zheng L, Deng W, et al. SVDNet for Pedestrian Retrieval[J]. 2 ...
- 微信小程序左滑显示按钮demo
wxml结构(删除部分代码): <view class="chapter-item" wx:for="{{klgData}}" data-index=&q ...
- 【NS2】有线和无线混合场景 (转载)
1. 创建简单的有线-无线混合场景 上一节建立的无线仿真可以支持多跳adhoc网络或wirelesslan.但是,我们可能需要对经过有线网络连接的多个无线网络进行仿真,或者说我们需要对有线-无线混合网 ...
- Autodesk 卸载工具,一键完全彻底卸载删除autodesk软件专门卸载工具
autodesk卸载工具(AUTO Uninstaller)是专门为了针对autodesk类软件卸载不干净而导致autodesk安装失败问题进行研发的autodesk一键卸载工具.现在虽然360或一些 ...
- hdu 2089 不要62【数位dp】
HDU 2089 求给定区间内不含62和4的数的个数. 数位dp入门.从这里我清楚了一些数位dp的用法.比如limit是判断是否达到上界,而且需要判断(!limit)..比如若题目要求不含11的个数, ...
- PHP判断图片格式的七种方法小结
<?php $imgurl = "http://www.jb51.net/images/logo.gif"; //方法1 echo $ext = strrchr($imgur ...
- SP2-0642: SQL*Plus internal error state 2130, context 0:0:0
..experience, Working case SP2-0642: SQL*Plus internal error state 2130, context 0:0:0 2016-10-09 没有 ...
- MySQL 获取当前月的天数
select curdate(); --获取当前日期 select DATE_ADD(curdate(),interval -day(curdate())+ ...