poj 1797 Heavy Transportation(最短路径Dijkdtra)
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 26968 | Accepted: 7232 |
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
first line contains the number of scenarios (city plans). For each city
the number n of street crossings (1 <= n <= 1000) and number m of
streets are given on the first line. The following m lines contain
triples of integers specifying start and end crossing of the street and
the maximum allowed weight, which is positive and not larger than
1000000. There will be at most one street between each pair of
crossings.
Output
The
output for every scenario begins with a line containing "Scenario #i:",
where i is the number of the scenario starting at 1. Then print a
single line containing the maximum allowed weight that Hugo can
transport to the customer. Terminate the output for the scenario with a
blank line.
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1:
4
题目大意,有n个城m条边,每个边有个最大的通过量,求1城市到n城市的一条最大通路容量是多少
迪杰斯特拉算法的变形,松弛条件改为道路容量为道路上容量最小的边,然后在选容量最大的路
ac代码如下:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<memory.h>
using namespace std;
long map[][];
long dp[],n;
bool v[];
void dij(int ii){
for(int i=;i<=n;i++){
dp[i]=map[ii][i];
}
dp[ii]=;v[ii]=;
int T=n;
while(T--){
int k=-,s;
for(int i=;i<=n;i++){//找下一条边
if(dp[i]>k&&!v[i]){
k=dp[i];
s=i;
}
}
v[s]=;
if(s==n)return;
for(int i=;i<=n;i++){//利用下一条边进行松弛
if(!v[i]&&dp[i]<min(dp[s],map[s][i])){
dp[i]=min(dp[s],map[s][i]);
}
}
}
}
int main(){
long T,m,s,e,c,ca=;
cin>>T;
while(T--){
cin>>n>>m;
memset(v,,sizeof(v));
memset(dp,,sizeof(dp));
memset(map,,sizeof(map));
for(int i=;i<=m;i++){
cin>>s>>e>>c;
map[s][e]=map[e][s]=max(map[s][e],c);
}
dij();
cout<<"Scenario #"<<ca++<<":"<<endl;
cout<<dp[n]<<endl<<endl;
}
return ;
}
提交结果:
poj 1797 Heavy Transportation(最短路径Dijkdtra)的更多相关文章
- 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 (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- 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 (最大生成树)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
随机推荐
- 【Linux系统】防暴力破解
在日志文件/var/log/secure 中可以看到涉及到安全方面的日志,可以查看是否有人尝试暴力破解及是否成功,对于肉鸡行为有一定帮助 思路基本上都是加强密码的复杂度,增加iptables配置黑名单 ...
- jQuery.form.js jQuery ajax异步提交form
jQuery.form.js是一个form插件,支持ajax表单提交和ajax文件上传. 官网下载地址:http://plugins.jquery.com/form/ API ajaxForm 增加所 ...
- Eclipse上安装springsource-tool-suite(zhuan)
http://jingyan.baidu.com/article/1612d5005fd087e20f1eee10.html *********************************** s ...
- Akka学习博客
http://www.iteblog.com/archives/1157 以示例介绍了actor模型.
- Python策略模式实现源码分享
1.让一个对象的某个方法可以随时改变,而不用更改对象的代码 2.对于动态类型的Python语言,不需要定义接口 3.基本的实现方法:用类作为参数传递 例如: 12_eg3.py class Movea ...
- iOS 国际化多语言设置 xcode7
iOS 国际化多语言设置 方式一: 1. 在storyboard中创建好UI,然后在 project 里面 Localizables 栏目里面,添加你需要的语言:默认是Englist; 比如这里我添 ...
- 【bzoj1043】下落的圆盘
[bzoj1043]下落的圆盘 题意 有n个圆盘从天而降,后面落下的可以盖住前面的.求最后形成的封闭区域的周长.看下面这副图, 所有的红色线条的总长度即为所求. \(1\leq n\leq 1000\ ...
- [bootstrap] 栅格系统和布局
1.简介 栅格系统(grid systems),也称为“网格系统”,运用固定的格子设计版面布局,风格工整简洁.是从平面栅格系统演变而来. Bootstrap建立在12列栅格系统.布局.组件之上.以规则 ...
- HTML5自学笔记[ 23 ]canvas绘图基础7
变换矩阵: transform(a,b,c,d,e,f),多次使用该函数,效果是多次状态改变的累加: setTransform(a,b,c,d,e,f),会忽略之前的变换,从起始状态开始改变.
- java多线程下如何调用一个共同的内存单元(调用同一个对象)
/* * 关于线程下共享相同的内存单元(包括代码与数据) * ,并利用这些共享单元来实现数据交换,实时通信与必要的同步操作. * 对于Thread(Runnable target)构造方法创建的线程, ...