POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
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的路径中,找一条最短边的最大值。也就是在这个路径中,这条边的长度小于这条路径中所有边,但是大于这条路径之外的所有边长度。 解题思路:最短边最大化。d[i]表示从源点到i点的最短边长度。跟POJ 2253解法类似。
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
const int maxn = 1e4+200;
const int INF = 0x3f3f3f3f;
int n,m;
struct HeapNode{
int d;
int u;
bool operator < (const HeapNode &rhs)const {
return d < rhs.d; //
}
};
struct Edge{
int from,to,dist;
};
vector<Edge>edge;
vector<int>G[maxn];
priority_queue<HeapNode>PQ;
int d[maxn] , vis[maxn];
void AddEdge(int u,int v,int w){
edge.push_back((Edge){u,v,w});
m = edge.size();
G[u].push_back(m-1);
}
void init(){
for(int i = 0; i<= n;i++){
G[i].clear();
}
edge.clear();
}
void Dijstra(int s){
for(int i = 0;i <= n; i++){
d[i] = 0;
}
d[s] = INF;
memset(vis,0,sizeof(vis));
PQ.push( (HeapNode){d[s],s} );
while(!PQ.empty()){
HeapNode x = PQ.top();
PQ.pop();
int u = x.u;
if(vis[u]) continue;
vis[u] = 1;
for(int i = 0; i < G[u].size(); i++){
Edge & e = edge[G[u][i]];
if(vis[e.to]) continue;
if(d[e.to] < min(d[e.from] , e.dist)){
d[e.to] = min(d[e.from], e.dist);
PQ.push((HeapNode){ d[e.to], e.to });
}
}
}
}
int main(){
int T,cnt = 0,mm;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&mm);
init();
int a,b,c, i;
for( i = 1; i <= mm; i++){
scanf("%d%d%d",&a,&b,&c);
a--,b--;
AddEdge(a,b,c);
AddEdge(b,a,c);
}
Dijstra(0);
printf("Scenario #%d:\n",++cnt);
printf("%d\n",d[n-1]);
puts("");
}
return 0;
}
POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】的更多相关文章
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)
题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- 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
题目链接: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 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
随机推荐
- VisualGDB系列3:安装VisualGDB
根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 1 系统需求 系统需求如下: Micro ...
- 全面解析JS字符串和正则表达式中的match、replace、exec等函数
转自:https://www.jb51.net/article/87730.htm 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将 ...
- Mybaits整合Spring自动扫描 接口,Mybaits配置文件.xml文件和Dao实体类
1.转自:https://blog.csdn.net/u013802160/article/details/51815077 <?xml version="1.0" enco ...
- HTML input 标签不可编辑的 readonly 属性
1 <form action="form_action.asp" method="get"> Name:<input type="t ...
- Java学习路线-知乎
鼬自来晓 378 人赞同 可以从几方面来看Java:JVM Java JVM:内存结构和相关参数含义 · Issue #24 · pzxwhc/MineKnowContainer · GitHub J ...
- mysql--二进制日志(bin-log)
一.设置二进制日志 进制日志记录了所有的DDL和DML,但不包括各种查询.通过二进制日志,可以实现什么效果呢?二进制日志文件可以[实现灾难数据恢复],另外可以应用到[mysql复制数据同步].二进制日 ...
- 31、SAM文件中flag含义解释工具--转载
转载:http://www.cnblogs.com/nkwy2012/p/6362996.html SAM是Sequence Alignment/Map 的缩写.像bwa等软件序列比对结果都会输出这 ...
- filter与servlet的比较
filter与servlet的比较 主要从如下四个方面介绍他们之间的区别: 1.概念. 2.生命周期. 3 ...
- 实验楼Linux基础入门第一周
&&使用oschina的git服务器 1.创建了项目 https://git.oschina.net/abc99/wyq20169314 2.配置项目 (1)为项目添加公钥 项目管理- ...
- 以后尽量不用cin、cout啦
cout输出有问题(对于double,不同OJ处理的结果不一样),cin读入机制较scanf繁琐.慢!!!!!!!!