POJ1797:Heavy Transportation(改造Dijkstra)
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)的更多相关文章
- POJ1797 Heavy Transportation 【Dijkstra】
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 21037 Accepted: ...
- POJ--1797 Heavy Transportation (最短路)
题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...
- (Dijkstra) POJ1797 Heavy Transportation
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 53170 Accepted: ...
- 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 ...
- POJ1797 Heavy Transportation —— 最短路变形
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ1797 Heavy Transportation (堆优化的Dijkstra变形)
Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...
- poj1797 Heavy Transportation Dijkstra算法的简单应用
题目链接:http://poj.org/problem?id=1797 题目就是求所有可达路径的其中的最小值边权的最大值 即对于每一条能够到达的路径,其必然有其最小的承载(其实也就是他们自身的最大的承 ...
- (简单) POJ 1797 Heavy Transportation,Dijkstra。
Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...
- POJ 1797 Heavy Transportation(Dijkstra运用)
Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can no ...
随机推荐
- dedecms织梦首页被篡改 网站被黑被跳转的解决办法建议
2018年的中秋节即将来临,我们Sine安全公司,最近接到很多用dedecms程序的企业公司网站客户的反馈,说是公司网站经常被篡改,包括网站首页的标题内容以及描述内容,都被改成了什么北京赛车,北京PK ...
- go学习笔记-基础类型
基础类型 布尔值 布尔值的类型为bool,值是true或false,默认为false. //示例代码 var isActive bool // 全局变量声明 var enabled, disabled ...
- [Cracking the Coding Interview] 4.5 Validate BST
Implement a function to check if a binary tree is a binary search tree. 这道题很经典,让我们判断一棵树是不是二叉查找树.但是首先 ...
- java第二章 变量和运算符
Java 基础应用编程—— 变量和运算符 1.Java程序结构 数据类型:确定要存储在内存中的数据的类型. 变量:是存储数据的基本单元 2.变量的概念 变 ...
- linux execl()函数
关于execl()函数族的用法不在赘述,其他博主介绍的很详细.下面说下作者在使用该函数时所犯的错误: 作者想通过使用execl()函数在子进程中调用其他函数,起初楼主是 这样用的: if((a = e ...
- MySQL 从入门到删库
基本操作 登陆指令 mysql -u用户名 -p密码(可以非明文输入) -h主机/IP -D端口 --prompt 提示符 修改提示符 \D 日期 \d 当前数据库 \h 服务器名 \u 用户名 // ...
- RHCE7认证学习笔记17——KickStart安装系统
一.自动化安装系统工具 1.Cobbler 另一个自动化安装工具: 2.Kickstart 二.使用kickstart自动化安装系统 服务器安装的软件: 1.dhcp服务 [root@lin ...
- Linux 下 PHP 扩展Soap 编译安装
1.进入 PHP 的软件包 pdo 扩展目录中(注:不是 PHP 安装目录) [root@tester /]# /home/tdweb/php-5.4.34/ext/soap 执行 phpize 命令 ...
- 基本数据类型的成员变量放在jvm的哪块内存区域里?
几个月前自己提问的一个问题没人回答,现在突然翻到,自己回答下: 问题: 比如class{private int i;}如上代码,之前一直以为基本数据类型都是放在虚拟机栈中的,最近看了<深入理解j ...
- spark1.6.0伪分布式搭建
环境: hadoop2.6.0 jdk1.8 ubuntu 14.04 64位 1 安装scala环境 版本是scala-2.10.6,官网下载地址http://www.scala-lang.org/ ...