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 ...
随机推荐
- LAMP 1.2 Apache编译安装问题解决
这个错误安装 yum install -y gcc error: mod_deflate has been requested but can not be built due to prerequi ...
- position应用之相对父元素的定位
分别添加以下style即可: 父元素position:relative; 子元素position:absolute; right:0px; bottom:0px;
- JDBC编程之数据查询
----------------siwuxie095 JDBC 编程之数据查询 首先下载 MySQL 的 JDBC 驱动 ...
- PCLVisualizer可视化类(4)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=168 多视口显示 所示,并进行比较分析,利用不同的搜索半径,基于同一点云计算 ...
- super关键字主要有以下两种用途
super关键字主要有以下两种用途. 1.调用父类的构造方法 子类可以调用由父类声明的构造方法.但是必须在子类的构造方法中使用super关键字来调用.其具体的语法格式如下: super([参数列表]) ...
- 《精通Spring4.X企业应用开发实战》读后感第六章(使用外部属性文件)
- change和onchange、click和onclick的区别
change和onchange.click和onclick的区别: onchange和onclick都是js方法 可以在标签元素上使用 <input onchange="" ...
- 7.23实习培训日志-JDBC
总结 今天下午考试,JDBC,这个本身很简单,但是需要我们Dockerfile+Docker Compose运行,这个东西就很复杂.原来学习时没有怎么看,这一次就很懵,完全不知道怎么弄,反正环境都没有 ...
- redis系列:通过通讯录案例学习hash命令
前言 这一篇文章将讲述Redis中的hash类型命令,同样也是通过demo来讲述,其他部分这里就不在赘述了. 项目Github地址:https://github.com/rainbowda/learn ...
- sql获取当日减去几天的几天前日期
CONVERT(varchar(10),DATEADD(DAY, -220 ,CONVERT(nvarchar(10),getdate(),23)),23)