题目链接:

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. 使用 PyCharm 添加 第三方 依赖库

    背景 最近开始搞python, 需要帮助算法同事一起调试程序,在本地安装python以后使用 pip 来安装第三方库. 但是算法同事一直使用的是PyCharm 这个IDE,所以需要与他一起调试的时候也 ...

  2. Python中range()和len()

  3. Struts2-整理笔记(一)介绍、搭建、流程、详解struts.xml

    Struts2是一种前端的技术框架 替代Servlet来处理请求   Struts2优势 自动封装参数 参数校验 结果的处理(转发|重定向) 国际化 显示等待页面 表单的防止重复提交   搭建框架:导 ...

  4. struts2 使用filter解决中文乱码问题

    1.编写fliter的代码 import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChai ...

  5. Python学习_05_条件、循环

    条件 和其他语言类似,python中使用if...elif...else来形成分支,支持三目操作符 ?:,python中没有switch,但是缩进的特性让if...elif...else的结构同样便于 ...

  6. c3p0使用记录

    首先要导入c3p0包.c3p0下载解压后,lib目录下有三个包,使用mysql的话,只需要导入c3p0-0.9.5.2.jar,mchange-commons-java-0.2.11.jar. 要连接 ...

  7. java内存溢出问题

    相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的认识. 在解决j ...

  8. vue:简单方法替代vuex或者bus

    兄弟组件,隔代组件传值很麻烦,方法虽然多,但都各有缺点. vuex: 适合数据量大,并且函数集中处理. bus:适合数据虽少,却不得不用的时候,维护困难. root:这儿指将值挂在root组件上,需要 ...

  9. Python+selenium+eclipse+pydev自动化测试环境搭建

    一.        安装python 1.下载安装python 可访问python的官方网站:http://www.Python.prg找到下载页面下载需要的版本,可下载python2.x或者pyth ...

  10. Python的特性(property)

    特性(property) 特性是对类的一个特定属性进行拦截,在操作这个属性时,执行特定的函数,对属性的操作进行拦截. 特性的实现 特性使用property类来实现,也可以使用property装饰器实现 ...