题目链接:http://poj.org/problem?id=1797

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 to n. Your task is to find the maximum weight that can be transported from crossing (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 ( <= n <= ) 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 . 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 . 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 Sample Output Scenario #:

题目大意:有N个城市,有M条路,每条路上有一个最大承重量,问从1到N的道路上能通过的最大承重量是多少?

思路:就是求最大生成树上的最小值,dis【i】表示1到i的最大承重数

#include<stdio.h>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include <stack>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof(a))
#define N 1010
int Map[N][N];
int vis[N],dis[N],n,minn;
int dij(int s)
{
vis[s]=;
for(int i=;i<=n;i++)
dis[i]=Map[s][i];
for(int i=;i<n;i++)
{
int ans=-INF,k=;
for(int j=;j<=n;j++)
{
if(!vis[j] && ans<dis[j])
ans=dis[k=j]; /// 找到之中的最大值
}
vis[k]=;
for(int j=;j<=n;j++)
{
if(!vis[j])
{
int m=min(Map[k][j],dis[k]) ///经过k点到j点,取从1到k点的最大承重量与从k到j点之间的最大承重量之间较小的值
}
dis[j]=max(dis[j],k);///从1到j是否要经过k点,如果经过k点的最大承重量大就经过k点
}
}
return dis[n];///1到每个点的最大承重量
}
int main()
{
int t,m,x,b,l,con=;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&m);
met(Map,);
for(int i=;i<m;i++)
{
scanf("%d %d %d",&x,&b,&l);
Map[x][b]=Map[b][x]=l; ///道路是双向的
}
met(vis,);
printf("Scenario #%d:\n%d\n\n",con++,dij());
}
return ;
}

(POJ 1797) Heavy Transportation 最大生成树的更多相关文章

  1. POJ 1797 Heavy Transportation (最大生成树)

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

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

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

  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 (Dijkstra变形)

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

  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(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  8. POJ 1797 Heavy Transportation (Dijkstra变形)

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

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

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

  10. POJ 1797 Heavy Transportation (Dijkstra)

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

随机推荐

  1. C++11 新特性之 Lambda表达式

    lambda表达式能够用于创建并定义匿名的函数对象,以简化编程工作 Lambda的语法例如以下: [函数对象參数](操作符重载函数參数)->返回值类型{函数体} []内的參数指的是Lambda表 ...

  2. 实例源码--Android旋转式菜单(效果很炫)

    下载源码   技术要点: 1.旋转式菜单功能实现 2.动画的应用 3.自定义控件的使用 ...... 详细介绍: 1. 旋转式菜单功能实现 本套例子通过自定义布局与动画的综合使用,实现了旋转式菜单效果 ...

  3. Storm中的LocalState 代码解析

    官方的解释这个类为: /** * A simple, durable, atomic K/V database. *Very inefficient*, should only be * used f ...

  4. JavaScript之对数组中元素进行增删改

    JavaScript中数据类型无非是:简单类型+复杂类型,什么是简单什么又是复杂.从电脑物理存储上讲,简单就是所见即所得,你看见什么,电脑里面存的就只是什么,并不会因为一些关系(比如引用)而多出一部分 ...

  5. I2C驱动程序

    i2c_add_driver i2c_register_driver driver->driver.bus = &i2c_bus_type; driver_register(&d ...

  6. rpm命令使用说明

    RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序” rpm 执行安装包二进制包(Binary)以及源代码包(Source)两种 ...

  7. Hibernate悲观锁/乐观锁

    如果需要保证数据访问的排它性,则需对目标数据加"锁",使其无法被其它程序修改 一,悲观锁 对数据被外界(包括本系统当前的其它事务和来自外部系统的事务处理)修改持保守态度,通过数据库 ...

  8. [改善Java代码]让工具类不可实例化

    建议42: 让工具类不可实例化 Java项目中使用的工具类非常多,比如JDK自己的工具类java.lang.Math.java.util.Collections等都是我们经常用到的.工具类的方法和属性 ...

  9. 关于cmd模式下切换目录

    cmd下切换目录: 经常犯下的错误一: 在默认路径下输入 cd D: 想切换到D盘但是会出现上面的现象. 正确的的做法是直接输入要转移到的盘符: D:  就可以了. 在这种情况下再输入cd D:

  10. 关于windows中的快捷键

    Windows快捷键大全编辑 目录1快捷方式 2IE浏览器 3小键盘 4WIN键 5资源管理器 6对话框7我的电脑 8放大程序 9辅助选项 10XP键盘 11对话框 12自然键盘13辅助键盘 14键盘 ...