(Dijkstra) POJ1797 Heavy Transportation
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 53170 | Accepted: 13544 |
Description
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<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = ;
int mp[maxn][maxn],dis[maxn],vis[maxn];
int edge,node;
int num;
void dijkstra(){
for(int i = ; i <= node; i++){
dis[i] = mp[][i];
}
for(int i = ; i < node; i++){
int mn = -,u;
for(int j = ; j <= node; j++){
if(vis[j] == && dis[j] > mn){ //dis[]是为了找到最大承载量。找到没有标记的点。
mn = dis[j];
u = j;
}
}
vis[u] = ;
for(int j = ; j <= node; j++){
if(vis[j] == && dis[j] < min(dis[u],mp[u][j])){ //松弛,由于最大承载量是有限制,需要要选择最小的。
dis[j] = min(dis[u],mp[u][j]);
}
}
} }
int main(){
int T;
num = ;
scanf("%d",&T);
while(T--){
num++;
scanf("%d%d",&node,&edge);
for(int i = ; i <= node; i++){
for(int j = ; j <= node; j++){
mp[i][j] = ; //求最大当然要初始化最小。
}
}
memset(vis,,sizeof(vis));
int m,n,t;
for(int i = ; i < edge; i++){
scanf("%d%d%d",&m,&n,&t);
mp[m][n] = mp[n][m] = t; //此题是无向图中求从1到node的最短路。无向图。
}
dijkstra();
printf("Scenario #%d:\n%d\n\n",num,dis[node]);
}
return ;
}
(Dijkstra) POJ1797 Heavy Transportation的更多相关文章
- POJ--1797 Heavy Transportation (最短路)
题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...
- POJ1797 Heavy Transportation 【Dijkstra】
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 21037 Accepted: ...
- POJ1797 Heavy Transportation —— 最短路变形
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ1797 Heavy Transportation (堆优化的Dijkstra变形)
Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...
- poj1797 Heavy Transportation Dijkstra算法的简单应用
题目链接:http://poj.org/problem?id=1797 题目就是求所有可达路径的其中的最小值边权的最大值 即对于每一条能够到达的路径,其必然有其最小的承载(其实也就是他们自身的最大的承 ...
- POJ1797 Heavy Transportation(SPFA)
题目要求1到n点的最大容量的增广路. 听说是最短路求的,然后乱搞就A了.. 大概能从Bellman-Ford的思想,dk[u]表示从源点出发经过最多k条边到达u点的最短路,上理解正确性. #inclu ...
- poj1797 - Heavy Transportation(最大边,最短路变形spfa)
题目大意: 给你以T, 代表T组测试数据,一个n代表有n个点, 一个m代表有m条边, 每条边有三个参数,a,b,c表示从a到b的这条路上最大的承受重量是c, 让你找出一条线路,要求出在这条线路上的最小 ...
- POJ1797 Heavy Transportation
解题思路:典型的Kruskal,不能用floyed(会超时),上代码: #include<cstdio> #include<cstring> #include<algor ...
- [POJ1797] Heavy Transportation(最大生成树 || 最短路变形)
传送门 1.最大生成树 可以求出最大生成树,其中权值最小的边即为答案. 2.最短路 只需改变spfa里面的松弛操作就可以求出答案. ——代码 #include <queue> #inclu ...
随机推荐
- Linux 学习 (二) 文件处理命令
Linux达人养成计划 I 学习笔记 ls [选项] [文件或目录] -a: 显示所有文件,包括隐藏文件 -l: 显示详细信息 -d: 查看目录属性 -h: 人性化显示文件大小 -i: 显示inode ...
- mobile deeplearning
框架: 腾讯ncnn https://github.com/Tencent/ncnn 百度mobile-deep-learning https://github.com/baidu/mobile-de ...
- CF821C Okabe and Boxes
题目链接 题目大意 模拟栈的操作,要求从1~n依次弹出,若不符合可以排序,且不会有不合法情况,求最少排序次数. 思路 由于一定没有不合法情况,所以每次不符合顺序时可以直接清空,遇到栈为空时仍然要求弹出 ...
- C#开发轻松入门--笔记
第一章 1-1 .NET简介 (02:11) 1-2 Visual Studio简介及安装 (03:23) 1-3 创建C#控制台程序 (04:14) 1-4 练习题 1-5 程序界面各部分介绍 (0 ...
- JAVA优先级队列元素输出顺序测试
package code.test; import java.util.Comparator; import java.util.Iterator; import java.util.Priority ...
- js判断一个元素是否在数组中
js判断一个元素是否在数组中 var arr = ['a','s','d','f']; console.info(isInArray(arr,'a'));//循环的方式 function isInAr ...
- 学习Android过程中遇到的问题及解决方法——网络请求
在学习Android的网络连接时遇到崩溃或异常(出现的问题就这两个,但是不稳定)的问题,先上代码,看看哪里错了(答案在文末) activity_main.xml: <?xml version=& ...
- [luogu2503][HAOI2006]均分数据【模拟退火】
题目描述 已知N个正整数:A1.A2.--.An .今要将它们分成M组,使得各组数据的数值和最平均,即各组的均方差最小.均方差公式如下: 分析 模拟退火学习笔记:https://www.cnblogs ...
- 763. Partition Labels
我一开始看数据范围很小,没怎么想就直接暴力了. 暴力的思路是: 对于每一段S的前缀,这个前缀中的每一个字母都不应该在前缀的补集中出现,所以直接循环i:0 to S.length然后对于每一次循环,再循 ...
- centos7下mysql半同步复制原理安装测试详解
原理简介: 在MySQL5.5之前,MySQL的复制其实都是异步复制(见下图),主库和从库的数据之间存在一定的延迟,这样存在一个隐患:当在主库上写入一个事务并提交成功,而从库尚未得到主库推送的BinL ...