(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 ...
随机推荐
- vue-cli: preset预设
preset:预设 vue create demo01 过程中,会保存预设,自动保存着 .vuerc 文件中 .vuerc 文件的位置:C:\Users\Administrator C:\Users\ ...
- Python入门-编写抓取网站图片的爬虫-正则表达式
//生命太短 我用Python! //Python真是让一直用c++的村里孩子长知识了! 这个仅仅是一个测试,成功抓取了某网站1000多张图片. 下一步要做一个大新闻 大工程 #config = ut ...
- Django+Xadmin打造在线教育系统(八)
首页和全局404,500配置 轮播图 公开课 授课机构 新建view ## 首页view class IndexView(View): def get(self,request): # 取出轮播图 a ...
- Codeforces191 C. Fools and Roads
传送门:>Here< 题意:给出一颗树,和K次操作.每次操作给出a,b,代表从a到b的路径上所有边的权值都+1(边权最开始全部为0).最后依次输出每条边最终的权值 解题思路: 由于n非常大 ...
- selenium+python启动Firefox浏览器失败问题和点击登陆按钮无效问题
问题1:使用python+selenium编写脚本调用Firefox时报错:
- CODEFORCES掉RATING记 #3
比赛:Codeforces Round #426 (Div. 2) 时间:2017.7.30晚 开场先看AB A:给你两个方向,和旋转次数(每次旋转90度),问你旋转方向是什么 B:给你一个字符串,问 ...
- 睡眠麻痹 CSP HSP
睡眠麻痹 CSP HSP 来源 https://www.zhihu.com/question/29666875/answer/65480583 俗名“鬼压床”.“鬼压身”或者“梦魇”的,学名叫睡眠麻痹 ...
- 【APIO2018】新家(线段树)
[APIO2018]新家(线段树) 题面 UOJ 洛谷 BZOJ 题解 论比赛时想不到二分的危害,就只能Cu滚粗 既然不要在线,那么考虑离线做法. 既然时间是区间,那么显然按照时间顺序处理答案. 显然 ...
- IISEXPRESS64位运行
调试时使用IISEXPRESS 64位.经网上查找这样开启
- 编译安装Nginx和PHP(带编译mysql)
应用场景:目前常见的LNMP架构中很多服务都采用nginx+fastcgi+php来提供服务. 测试环境:Centos 7.2 / Nginx 1.12.0 / PHP 5.6 配置步骤: 1. 下载 ...