(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 ...
随机推荐
- css的特性
一.继承性: 继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代. /* 不具有继承性的css样式: */p{border:1px solid red;} 二.特殊性(优先 ...
- July 算法习题 - 字符串4(全排列和全组合)
https://segmentfault.com/a/1190000002710424 思想:当前层各节点首元素不同,则各节点的剩余元素也不同:下一层节点交换范围为首元素以外的元素 全排列算法: vo ...
- 小程序——Tab切换
<view class="body"> <view class="nav bc_white"> <view class=" ...
- python基础数据类型--list列表
列表: 列表是python中的基础数据类型之一,其他语言中也有类似于列表的数据类型,比如js中叫数组,他是以[]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如: li = [‘alex ...
- windows 环境下通过运行快速启动程序
在windows环境下,我们可以使用一些系统内置的快捷键来快速启动我们想要的应用程序,我这里举例几个我经常使用的,比如: 快捷键 功能说明 services.msc 查看系统服务 gpedit.ms ...
- hbase系列
jvmhttps://www.cnblogs.com/jiyukai/p/6665199.html hbase https://blog.csdn.net/lizhitao/article/detai ...
- bzoj1559 [JSOI2009]密码
题目链接:[JSOI2009]密码 我们先看第一问:输出方案数 我们把所有给出来的串丢到AC自动机里面去,然后在建出来的\(trie\)图上跑dp 由于\(n\leq 10\)我们很自然的就想到了状压 ...
- @ResponseBody注解
作用 @ResponseBody注解表示该方法的返回结果直接写入HTTP response body中 原理 在使用此注解之后跳过视图处理器,将返回的对象通过适当的转换器转换为指定的格式之后,直接将数 ...
- 【BZOJ3157/3516】国王奇遇记(数论)
[BZOJ3157/3516]国王奇遇记(数论) 题面 BZOJ3157 BZOJ3516 题解 先考虑怎么做\(m\le 100\)的情况. 令\(f(n,k)=\displaystyle \sum ...
- 【BZOJ5321】[JXOI2017]加法(贪心)
[BZOJ5321][JXOI2017]加法(贪心) 题面 BZOJ 洛谷 题解 显然二分答案,算一下每个点至少要覆盖的次数.从左往右考虑如果这个点覆盖次数不够,就会选择覆盖这个点的.右端点最大的线段 ...