题目链接:

http://poj.org/problem?id=1797

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

题意描述:
输入路口数及道路数以及每条路的承重量
计算并输出有最大承重量路径中的最小承重量(有点绕,其实就是最结实的那条路径中最不结实的一段路限重是多少)
解题思路:
最短路径问题的变型,处理数据使用迪杰斯特拉算法即可。
题目很经典,另外
最长路径最小权值题目 请参考博客:http://www.cnblogs.com/wenzhixin/p/7336948.html
最短路径双重最小权值题目参考博客:http://www.cnblogs.com/wenzhixin/p/7405802.html
代码实现:
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int inf=;
int d[],e[][],book[];
int main()
{
int t,n,m,i,j,t1,t2,t3,max,u,k,c=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
for(j=;j<=n;j++)
e[i][j]=-inf;//初始化为无穷小值,后面求最长路径下的情况
for(i=;i<=m;i++)
{
scanf("%d%d%d",&t1,&t2,&t3);
e[t1][t2]=e[t2][t1]=t3;
}
for(i=;i<=n;i++)
d[i]=e[][i];
memset(book,,sizeof(book));
book[]=;
for(i=;i<=n-;i++)
{
max=-inf;
for(j=;j<=n;j++)//找到1到各个非树结点中(最小承重量)的最大承重量
{
if(!book[j] && d[j] > max)
{
max=d[j];
u=j;
}
}
book[u]=;
for(k=;k<=n;k++)
{//更新1到各个非树结点的最小承重量为
//之前的最大承重量 和 u到各个非树结点的承重量 中较小者 大于之前结果的承重量
if(!book[k] && d[k] < min(d[u],e[u][k]))//c++提交
d[k]=min(d[u],e[u][k]);
}
}
printf("Scenario #%d:\n%d\n\n",c++,d[n]);
//d中存的是从1到每个结点的最小承重量
}
return ;
}

												

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 SPFA变形

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

  3. POJ 1797 Heavy Transportation (Dijkstra)

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

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

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

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

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

  6. POJ 1797 Heavy Transportation

    题目链接: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. Dijkstra(变形) POJ 1797 Heavy Transportation

    题目传送门 题意:求1到n的最大载重量 分析:那么就是最大路上的最小的边权值,改变优先规则. #include <cstdio> #include <algorithm> #i ...

  9. poj 1797 Heavy Transportation(Dijkstar变形)

    http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...

随机推荐

  1. 为什么要学ADO.NET。。。什么是ADO.NET。。。

    之前学的 •只能在查询分析器里查看数据,操作数据,我们不能让普通用户去学sql,所以我们搭建一个界面(Web Winform)让用户方便的操作数据库中的数据.   •ADO.NET就是一组类库,这组类 ...

  2. 进程间通信 ipcs

    在linux系统上借助ipcs命令可以方便地查看进程间通信状态 操作系统:centos7.3 x86_64 应用软件: oracle12c

  3. 防盗链与token运用

    为什么要防盗链? 例如手机/PC应用,如果有人知道你的api地址,和应用格式,那么他人就可以利用这个接口进行盗链:盗取/盗用里面的数据. 防盗链特性: 1.因为是非开放性的,所以所有的接口都是封闭的, ...

  4. java接入创蓝253短信验证码

    说明 项目是springboot框架 1.短信配置文件 包含验证码发送路径.用户名.密码 chuanglan.requesturl= chuanglan.account= chuanglan.pswd ...

  5. C# 使用 CancellationTokenSource 终止线程

    http://blog.csdn.net/hezheqiang/article/details/51966511 我们在多线程中通常使用一个 C# 使用 CancellationTokenSource ...

  6. Java---hashCode()和equals()

    1.hashCode()和equals() API hashCode()和equals()都来自上帝类Object, 所有的类都会拥有这两个方法,特定时,复写它们. 它们是用来在同一类中做比较用的,尤 ...

  7. Python day 6(5) Python 函数式编程3

    一:装饰器 1 函数对象有一个__name__属性,可以拿到函数的名字 >>> def now(): ... print('2015-3-25') ... >>> ...

  8. icon图标和文字整体居中在button按钮

    icon图标和文字整体居中在button按钮 icon图标和文字整体居中 一般我们常做的button按钮是文字居中 现在这个需要icon图标和文字一起居中在背景色 <a href="# ...

  9. JS实现EasyUI ,Datagrid,合并单元格功能

    为了实现datagrid的合并单元格效果,datagrid的数据加载方式肯定是要写在JS文件内部的. 一:在JS内部添加Datagrid数据加载方法如下: $("#id").dat ...

  10. golang其实也可以优先调度

    线上一个服务有个严重问题,处理消息数1k/s提升不上去,经过查看是阻塞在了一个新加的函数上,这个函数负责收集信息,送到一个channel上,再由某个函数处理,这个处理函数很简单,看不出任何问题,最大的 ...