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 ...
随机推荐
- eclipse tomcat 无法加载导入的web项目,There are no resources that can be added or removed from the server. .
应该是项目自己的setting文件夹下的描述信息和.project文件的描述信息,不能适用于这个eclipse和tomcat. 解决方法: 1,找相同类型的工程(tomcat能引用的)2,把新建项目里 ...
- JavaScript接口
JavaScript中实现接口的方法有三种: 第一种,使用注释的方法实现接口 特点:(1)最简单,但是功能最弱(2)利用 interface和 implement"文字"(3)把他 ...
- Java探索之旅(14)——文本I/O与读写
1文件类File ❶封装文件或路径的属性.不包括创建和读写文件操作.File实例并不会实际创建文件.不论文件存在与否,可以创建任意文件名的实例.两种实例创建方式如下: ...
- Stream接口
数据读写可以看作是事件模式(Event)的特例,不断发送的数据块好比一个个的事件.读数据是read事件,写数据是write事件,而数据块是事件附带的信息.Node 为这类情况提供了一个特殊接口Stre ...
- 【Qt官方例程学习笔记】Getting Started Programming with Qt Widgets
创建一个QApplication对象,用于管理应用程序资源,它对于任何使用了Qt Widgets的程序都必要的.对于没有使用Qt Widgets 的GUI应用,可以使用QGuiApplication代 ...
- 2、Jquery_事件
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- redis命令集
查看使用运行服务:ping 关闭服务的连接:quit 切换数据库:select index 连接: redis-cli -h -a myPassword 查看密码: config get requir ...
- vue -- 正确的引入jquery
虽然vue中尽量不要使用jquery,但有时因为业务需求也不得不引入. 下载依赖 npm i jquery --save 全局配置的方法: 在webpack.base.conf.js里加入: var ...
- [Xcode 实际操作]三、视图控制器-(6)UINavigationController导航栏样式
目录:[Swift]Xcode实际操作 本文将演示对导航栏进行样式设置,以及更改导航顶部的提示区. 选择编辑第一个视图控制器文件. import UIKit class FirstSubViewCon ...
- click点击事件先后顺序的问题
//页面加载时,每秒钟调用一次var times = setInterval("loadFlws()","1000"); function loadFlws() ...