博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1797 Heavy Transportation (dijkstra 最小边最大)
阅读量:4310 次
发布时间:2019-06-06

本文共 3053 字,大约阅读时间需要 10 分钟。

Heavy Transportation

题目链接:

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:求最大边最小;

()
本质一样,更新时存在区别;
另外,求最大最小边时,不能把dis[s]初始化为0(即循环n-1次),否则更新失败;

代码:

#include
#include
#include
#include
#include
#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
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;}

转载于:https://www.cnblogs.com/Sunshine-tcf/p/5693985.html

你可能感兴趣的文章
IOS错误总结
查看>>
Win10系列:C#应用控件进阶4
查看>>
std::remove_if
查看>>
前端学HTTP之报文首部
查看>>
设置IIS 兼容32位DLL
查看>>
Python输出格式全总结
查看>>
Python数据结构 将列表作为栈和队列使用
查看>>
UVA 10815 Andy's First Dictionary【set】
查看>>
【CUDA 基础】3.2 理解线程束执行的本质(Part I)
查看>>
xshell配色
查看>>
php缓存
查看>>
【POJ2778】AC自动机+矩阵乘法
查看>>
自定义粘贴板-陈鹏
查看>>
Spark ML参考博客
查看>>
安装go语言,配置环境及IDE,只需3步
查看>>
本周最后一天——4.18
查看>>
JS类型、值和变量 笔记
查看>>
sqlalchemy和pymysql通过ssh连接远程mysql服务器
查看>>
eclipse主题样式
查看>>
谈谈如何在面试中发掘程序猿的核心竞争力zz
查看>>