Heavy Transportation

Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u

Description

Background 
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

The 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 题目大意:让你求从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、最短边最大化】的更多相关文章

  1. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  2. POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)

    题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...

  3. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  4. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  5. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  6. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  7. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  8. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  9. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

随机推荐

  1. Python错误处理和调试

    错误处理(try...except...finally...) try: print('try...') r = 10 / 0 print('result:', r) except ZeroDivis ...

  2. Android Studio的Android Monitor窗口中把标签拉出来之后放不回去的解决方法

    不小心把下图方框中的logcat标签拖出来之后, 就变成了图2的浮动窗口,发现logcat标签怎么也弄不回原来窗口中的位置中. 其实解决方法很简单,只要拖住下图浮动窗口中红框位置的logcat标签,然 ...

  3. 【java并发编程艺术学习】(四)第二章 java并发机制的底层实现原理 学习记录(二) synchronized

    章节介绍 本章节主要学习 Java SE 1.6 中为了减少获得锁 和 释放锁 时带来的性能消耗 而引入的偏向锁 和 轻量级锁,以及锁的存储结构 和 升级过程. synchronized实现同步的基础 ...

  4. javaScript之深度理解原型链

    经过多次的翻阅书籍终于对原型链在实际代码中的应用有了新的认识,但是不知道是否有错误的地方,还请大神多多指教. 构造函数.原型和实例的关系:每个构造函数都有一个原型对象funName.prototype ...

  5. HTTP返回码中301与302的区别

    一.官方说法 301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redirect: 301 代表永久性转移(Permanently Moved). 302 ...

  6. Zabbix_proxy的架设

    一.安装zabbix-proxy与导入数据库 1. 安装 zabbix-server $ sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/ ...

  7. Wannafly 锁

    题意: 现在有 $n$ 个人,每个人有一个已然给定的重要度 $a_i$,现有 K 个锁,每个锁有若干钥匙,分配给一些人,要求一群人能够打开全部 $K$ 把锁, 当且仅当他们重要度的和大于等于 $m$, ...

  8. 牛叉之nc命令

    nc是一款很不错的网络检测工具,以下是详细使用. 'nc.exe -h'即可看到各参数的使用方法. 基本格式:nc [-options] hostname port [ports] - nc -l - ...

  9. 数据访问层DAL

    我们已经根据设计好的pdm文件生成数据库,下面我们一起完成数据库访问层需要的工作 在dal类库上点击右键,添加,新建项 选择“ADO.NET实体数据模型”,会自动命名“Model1” 选择“来自数据库 ...

  10. 网页编程技术与实例 PDF扫描版

    本书主要包括:Web的概念,使用网页编辑工具制作网页,HTML语言的基本结构,JavaScrip和VBScript脚本语言的编程方法,ASP的概念,ASP对象的属性.方法和事件,SQL语言,数据库建议 ...