Heavy Transportation

Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 52728   Accepted: 13474

题目链接:http://poj.org/problem?id=1797

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号点所经路径的最小边权的最大值为多少。

题解:

其实本题也不是严格的dijkstra算法,只是利用了类似的贪心思想。

我们首先维护一个到当前点所有路径中的最小值,把它扔进优先队列里面,从优先队列里面每次取大值出来去更新与之相邻的点。

这里的正确性证明和dijkstra算法的证明类似,也就是说一个点去更新其它点后,不会被其他点又一次更新。

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = ;
int T;
int n,tot,m;
int head[N],vis[N],d[N];
struct Edge{
int u,v,next,w;
}e[N*N<<];
struct node{
int d,u;
bool operator < (const node &A)const{
return d<A.d;
}
};
void adde(int u,int v,int w){
e[tot].v=v;e[tot].next=head[u];e[tot].w=w;head[u]=tot++;
}
void Dijkstra(int s){
priority_queue <node> q;
memset(d,,sizeof(d));memset(vis,,sizeof(vis));
node now;d[s]=INF;
now.d=INF;now.u=s;
q.push(now);
while(!q.empty()){
node cur = q.top();q.pop();
int u=cur.u;
if(vis[u]) continue ;
vis[u]=;
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(d[v]<min(d[u],e[i].w)){
d[v]=min(d[u],e[i].w);
now.d=d[v];now.u=v;
q.push(now);
}
}
}
}
int main(){
cin>>T;
int cnt = ,first=;
while(T--){
cnt++;
scanf("%d%d",&n,&m);
memset(head,-,sizeof(head));tot=;
for(int i=;i<=m;i++){
int u,v,c;
scanf("%d%d%d",&u,&v,&c);
adde(u,v,c);adde(v,u,c);
}
Dijkstra();
printf("Scenario #%d:\n",cnt);
cout<<d[n]<<endl;
cout<<endl;
}
return ;
}

POJ1797:Heavy Transportation(改造Dijkstra)的更多相关文章

  1. POJ1797 Heavy Transportation 【Dijkstra】

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

  2. POJ--1797 Heavy Transportation (最短路)

    题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...

  3. (Dijkstra) POJ1797 Heavy Transportation

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

  4. POJ 1797 Heavy Transportation (Dijkstra变形)

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

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

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

  6. POJ1797 Heavy Transportation —— 最短路变形

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

  7. POJ1797 Heavy Transportation (堆优化的Dijkstra变形)

    Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...

  8. poj1797 Heavy Transportation Dijkstra算法的简单应用

    题目链接:http://poj.org/problem?id=1797 题目就是求所有可达路径的其中的最小值边权的最大值 即对于每一条能够到达的路径,其必然有其最小的承载(其实也就是他们自身的最大的承 ...

  9. (简单) POJ 1797 Heavy Transportation,Dijkstra。

    Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...

  10. POJ 1797 Heavy Transportation(Dijkstra运用)

    Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...

随机推荐

  1. Python学习:for 循环 与 range()函数

    for 循环   For … in 语句是另一种循环语句,其特点是会在一系列对象上进行迭代(Iterates),即它会遍历序列中的每一个项目 注意:  1.else 部分是可选的.当循环中包含它时,它 ...

  2. PHP中的mysql_unbuffered_query与mysql_query的区别

    对于mysql_query大家都很熟悉,下面先简单介绍下mysql_unbuffered_query mysql_unbuffered_query (PHP 4 >= 4.0.6, PHP 5) ...

  3. C语言Windows程序开发—TextOut函数介绍【第02天】

    (一)TextOut函数的参数介绍: BOOL TextOut ( //如果函数调用成功,返回TRUE,否则,返回FALSE HDC hdc, //用于显示字符串的控件ID int nXStart, ...

  4. LeetCode 二叉树的层次遍历 C++

    给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如:给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 返回其层 ...

  5. (数据科学学习手札31)基于Python的网络数据采集(初级篇)

    一.简介 在实际的业务中,我们手头的数据往往难以满足需求,这时我们就需要利用互联网上的资源来获取更多的补充数据,但是很多情况下,有价值的数据往往是没有提供源文件的直接下载渠道的(即所谓的API),这时 ...

  6. Windows下使用PHP Xdebug

    首先下载Xdebug的dll:http://xdebug.org/download.php 将dll文件放到php目录下的ext目录里面: 修改php.ini,根据自己的需要增加信息: [Xdebug ...

  7. 让Dreamweaver支持cshtml (MVC Razor环境)

    介绍:让Dreamweaver支持cshtml 正文: 如题,刚才搜了很久,都搜不到答案,幸好得到“包大人”(同事)的帮助,才得以解决. DW支持很多文件类型的代码提示,可是类型太多,不可能全部都有, ...

  8. linq里lambda写的join查询,并附加动态拼接的条件,条件为enum类型的查询

    因为查询条件不固定的原因,sql式的linq查询没法动态拼接条件. 网上搜的资料整理之后终于解决. 参考资料: enum使用 http://blog.csdn.net/slowlifes/articl ...

  9. 关于python的闭包与装饰器的实验

    首先看闭包,在嵌套函数内添加返回值,可以通过外部函数读取内部函数信息 #encoding=utf-8 #闭包应用 #先定义闭包函数,并使用 def outer(func): def inner(): ...

  10. 接口自动化测试框架Karate入门

    介绍 在这篇文章中,我们将介绍一下开源的Web-API自动化测试框架--Karate Karate是基于另一个BDD测试框架Cucumber来建立的,并且共用了一些相同的思想.其中之一就是使用Gher ...