(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 ...
随机推荐
- 转 JQuery:常用方法一览
出处 :http://www.cnblogs.com/Fooo/archive/2010/02/01/1661157.html 代码 Attribute:$(”p”).addClass(css中定义的 ...
- LodopJS文档式模版的加载和赋值
Lodop模版有两种方法,一种是传统的JS语句,可以用JS方法里的eval来执行,一种是文档式模版,是特殊格式的base64码,此篇博文介绍文档式模版的加载,文档式模版的生成以及传统JS模版的生成加载 ...
- 为WebRTC 应用部署Turn Server
部署WebRTC 或 SIP p2p 方案时经常会遇到p2p 无法穿透的环境, 这时就是TunServer 的用武之地了. 这里我们使用turnserver-0.7.3 下载confuse依赖库 wg ...
- How to helloworld on Xcode
create a mac app,click button to change label text? create project,click left window button on Main. ...
- Spring 使用介绍(十)—— 单元测试
一.概述 Spring测试框架提供了对单元测试的支持,以便使用spring的依赖注入和事务管理功能 maven依赖: <dependency> <groupId>junit&l ...
- 下载模板、Excel导入、导出
下载模板 /// <summary> /// 下载模板 /// </summary> /// <returns></returns> public Ac ...
- BZOJ2084[Poi2010]Antisymmetry——回文自动机
题目描述 对于一个01字符串,如果将这个字符串0和1取反后,再将整个串反过来和原串一样,就称作“反对称”字符串.比如00001111和010101就是反对称的,1001就不是.现在给出一个长度为N的0 ...
- Educational Codeforces Round 60 Div. 2
F:考虑对于每个字母对求出删掉哪些字符集会造成字符串不合法,只要考虑相邻出现的该字母对即可,显然这可以在O(np2)(或小常数O(np3))内求出.然后再对每个字符集判断是否能通过一步删除转移而来即可 ...
- Python中第三方模块requests解析
一.简述 Requests HTTP Library 二.模块框架 ''' __version__ _internal_utils adapters api auth certs compat coo ...
- Python_sys.argv 命令行参数获取使用方法
import sys print(sys.argv) """ 获取命令行参数 输入 python3 sys.argv_demo.py 输出: ['argv.py'] 输入 ...