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: ...
随机推荐
- Eclipse中查看JDK源码设置
设置方法如下: 1.路径 window-> Preferences -> Java -> Installed JRES 2.此时"Installed JRES"右 ...
- Hibernate--基本映射标签和属性介绍
一.映射文件的基本结构举例: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hiberna ...
- Windows Tomcat 安装
JDK的安装可以参考 http://www.cnblogs.com/emanlee/p/3702535.html ,然后安装apache-tomcat step1:http://tomcat.apac ...
- [HDOJ3635]Dragon Balls(并查集,路径压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3635 题意:有n个龙珠,n个城市.初始状态第i个龙珠在第i个城市里.接下来有两个操作: T A B:把 ...
- IEDA常用设置
安装插件步骤省略,暂时不需要 IDEA菜单详解:基本有对应的快捷键或者是图标Help系列:Find Action:作用:快速新建文件,Ctrl + Shift + AHelp Topics:作用:帮助 ...
- bzoj2792
首先想到二分答案是吧,设为lim 这道题难在判定,我们先不管将一个数变为0的条件 先使序列满足相邻差<=lim,这个正着扫一遍反着扫一遍即可 然后我们就要处理将一个数变为0的修改代价 当i变为0 ...
- IIS 10.0 无法安装 URL rewrite重写模块 2.0解决办法
[问题描述]系统升级到Windows10后,IIS是10.0的,发现无法安装 URLRewrite重写模块 2.0. [解决办法]打开注册表编辑器,在HKEY_LOCAL_MACHINE\SOFTWA ...
- C# 编写的串口通信程序
如果,翻看我之前的博客,会找到一篇用I/O模拟IIC通信的程序文章.好吧,如果找不到可以点击这里,这里就不在赘述了,系统也已经完全调试通过了. 今天的任务是,把测试得到的数据在上位机的界面上显示出来, ...
- vc2005编译ffmpeg以及ffplay
ffmpeg编译过程:1 http://ffmpeg.zeranoe.com/builds/下载官方提供的源码,win32库和dll.2 新建vc2005 console空工程,把ffmpeg.h,f ...
- Oracle中job的使用详解
我们在项目开发中,常常会有一些复杂的业务逻辑.使用oracle的存储过程,可以大大减少java程序代码的编写工作量,而且存储过程执行在数据库上,这样可以利用oracle的良好性能支持,极大地提高程序执 ...