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 最小边最大)的更多相关文章

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

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

  2. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

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

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

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

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

  5. POJ 1797 Heavy Transportation

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

  6. POJ 1797 Heavy Transportation SPFA变形

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

  7. POJ 1797 Heavy Transportation (Dijkstra变形)

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

  8. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

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

  9. POJ 1797 Heavy Transportation (最短路)

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

随机推荐

  1. [Codeforces137C]History(排序,水题)

    题目链接:http://codeforces.com/contest/137/problem/C 题意:给n对数,分别是一个事件的起始和终止时间.问被有几个事件被其他事件包含. 思路:先排序,按照起始 ...

  2. Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)

    题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1.  交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...

  3. UVa 11174 (乘法逆元) Stand in a Line

    题意: 有n个人排队,要求每个人不能排在自己父亲的前面(如果有的话),求所有的排队方案数模1e9+7的值. 分析: <训练指南>上分析得挺清楚的,把公式贴一下吧: 设f(i)为以i为根节点 ...

  4. UVa 11584 Partitioning by Palindromes【DP】

    题意:给出一个字符串,问最少能够划分成多少个回文串 dp[i]表示以第i个字母结束最少能够划分成的回文串的个数 dp[i]=min(dp[i],dp[j]+1)(如果从第j个字母到第i个字母是回文串) ...

  5. 定义 androidlistview 滚动条位置

    1.找到每一页的最后一条数据的位置 public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, ...

  6. 四种途径将HTML5 web应用变成android应用

    作为下一代的网页语言,HTML5拥有很多让人期待已久的新特性.HTML5的优势之一在于能够实现跨平台游戏编码移植,现在已经有很多公司在移动 设备上使用HTML5技术.随着HTML5跨平台支持的不断增强 ...

  7. 完整cocos2d-x编译Andriod应用过程

    作者:何卫 转载请注明,原文链接:http://www.cnblogs.com/hewei2012/p/3366969.html 其他平台移植:http://cocos2d.cocoachina.co ...

  8. HDU 5303 Delicious Apples 美味苹果 (DP)

    题意: 给一个长为L的环,起点在12点钟位置,其他位置上有一些苹果,每次带着一个能装k个苹果的篮子从起点出发去摘苹果,要将全部苹果运到起点需要走多少米? 思路: 无论哪处地方,只要苹果数超过k个,那么 ...

  9. Linux系统性能监控

    系统的性能指标主要包括CPU.内存.磁盘I/O.网络几个方面. 1. CPU性能 (1)利用vmstat命令监控系统CPU 该命令可以显示关于系统各种资源之间相关性能的简要信息,这里我们主要用它来看C ...

  10. .NET之美——C# 中的委托和事件

    C# 中的委托和事件 文中代码在VS2005下通过,由于VS2003(.Net Framework 1.1)不支持隐式的委托变量,所以如果在一个接受委托类型的位置直接赋予方法名,在VS2003下会报错 ...