POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation
题目链接:
http://acm.hust.edu.cn/vjudge/contest/66569#problem/A
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 Input
Scenario #1:
4
题意:
给出平面上的n个坐标,两两之间可联通;
求从#1到#n点的一条路径,使得其中最小的边最大;
题解:
直接用dijkstra实现即可;
dis[i]为起点s到当前点i的路径上最大的最小边;
本质与dijkstra求最短路一致;
POJ2253:求最大边最小;
(http://www.cnblogs.com/Sunshine-tcf/p/5693659.html)
本质一样,更新时存在区别;
另外,求最大最小边时,不能把dis[s]初始化为0(即循环n-1次),否则更新失败;
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mid(a,b) ((a+b)>>1)
#define LL long long
#define maxn 1100
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n, m;
int value[maxn][maxn];
int x[maxn],y[maxn];
int dis[maxn];
int pre[maxn];
bool vis[maxn];
void dijkstra(int s) {
memset(vis, 0, sizeof(vis));
memset(pre, -1, sizeof(pre));
for(int i=1; i<=n; i++) dis[i] = value[s][i];
for(int i=1; i<n; i++) {
int p;
int mindis = -1;
for(int j=1; j<=n; j++) {
if(!vis[j] && dis[j]>mindis)
mindis = dis[p=j];
}
vis[p] = 1;
for(int j=1; j<=n; j++) {
if(!vis[j] && dis[j] < min(dis[p],value[p][j])) {
dis[j] = min(dis[p], value[p][j]);
pre[j] = p;
}
}
}
}
int main(int argc, char const *argv[])
{
//IN;
int t,ca=1; cin>>t;
while(t--)
{
cin >> n >> m;
for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) value[i][j]=0;
while(m--){
int u,v,w; scanf("%d %d %d",&u,&v,&w);
value[u][v] = value[v][u] = w;
}
dijkstra(1);
printf("Scenario #%d:\n%d\n\n", ca++, dis[n]);
}
return 0;
}
POJ 1797 Heavy Transportation (dijkstra 最小边最大)的更多相关文章
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- 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 Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
随机推荐
- iOSbase64
ios中使用BASE64进行加密和解密的方法也很简单,可以直接用google-toolbox-for-mac的GTMBase64.h来实现google-toolbox-for-mac的对应地址如下: ...
- sublime-text3插件安装
sublime-text3和sublime-text2一样安装插件前都需要先安装,Package control ,然而安装Package control的代码和sublime-text2又不相同.如 ...
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
原博客地址:http://aijiawang-126-com.javaeye.com/blog/662336 在Activity中newSpinner是我把mContext传入,但是出了 andr ...
- BZOJ_1030_[JSOI2007]_文本生成器_(AC自动机+DP)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1030 给出一些单词,问长度为\(m\)的文章有多少文章中出现过任意一个或多个单词. 分析 文章 ...
- Samba 4.x.x全版本存在命令执行漏洞
Samba 4.0.0到4.1.10版本的nmbd(the NetBIOS name services daemon)被发现存在远程命令执行漏洞.CVE编号为CVE-2014-3560.目前官方已经发 ...
- rsync不存在用户处理CPU消耗拒绝服务漏洞
受影响产品: rsync 3.1.0 漏洞描述: CVE ID:CVE-2014-2855 rsync是一款文件同步管理软件. rsync处理不存在用户时存在安全漏洞,可消耗大量CPU资源,造成拒绝服 ...
- BZOJ3218: a + b Problem
题解: 先做60分... 考虑最小割,连边容量为需要付出的代价.不妨设在s割为黑色,t割为白色. (s,i,b[i])(i,t,w[i]) 关于奇怪,因为不是按份数来的.所以我们这样建图: (i,i+ ...
- Android开发之WebService介绍
经常有网友问:“在Android平台如何调用WebService”?经过沟通我发现,甚至有些朋友连什么是WebSerivce都不知道就在问怎么使用,更别说和WebService有关的SOAP.WSDL ...
- 图表框架HelloCharts(2)柱状图
1.效果图 2.xml代码 activity_column_chart.xml <FrameLayout xmlns:android="http://schemas.android.c ...
- AJAX在GBK编码页面中传中文参数乱码的问题
---恢复内容开始--- 页面编码是GBK的情况下传递中文有乱码,解决方法如下: 在ajax传递前用若是Array,JSON,等其它对象,可用JSON.stringfy字符串序列化后,赋值给ajax传 ...