(POJ 1797) Heavy Transportation 最大生成树
题目链接: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 最大生成树的更多相关文章
- POJ 1797 Heavy Transportation (最大生成树)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
随机推荐
- delphi res 字符串资源
delphi res 字符串资源 (2011/12/10 19:19:36) //res 字符串资源 //rc 文件:StringTablebegin0 "AAAA"1 " ...
- delphi Components[i]清除所有edit控件中的内容
(* 一般的清空combobox方法 combobox1.clear; ... combobox9.clear; *) procedure TForm1.Button1Click(Sender: ...
- 第二周02:Fusion ICP逐帧融合
本周主要任务02:Fusion 使用ICP进行逐帧融合 任务时间: 2014年9月8日-2014年9月14日 任务完成情况: 已实现将各帧融合到统一的第一帧所定义的摄像机坐标系下,但是由于部分帧之间的 ...
- 苹果开发工具:Xcode和Interface Builder
摘要:在Mac OS X上开发,首选Xcode继承开发环境.本文对开发工具套件中最重要的Xcode和Interface Builder两个工具做了简要介绍,并提供<苹果开发工具概述>PDF ...
- string2array($value);
/*** 将字符串转换为数组** @param string $data 字符串* @return array 返回数组格式,如果,data为空,则返回空数组*/if ( !function_exis ...
- mysql的二级索引
mysql中每个表都有一个聚簇索引(clustered index ),除此之外的表上的每个非聚簇索引都是二级索引,又叫辅助索引(secondary indexes). 以InnoDB来说,每个Inn ...
- 小白日记29:kali渗透测试之Web渗透-扫描工具-Vega
WEB扫描工具-Vega 纯图形化界面,Java编写的开源web扫描器.两种工作模式:扫描模式和代理模式[主流扫描功能].用于爬站.处理表单,注入测试等.支持SSL:http://vega/ca.cr ...
- Android进阶笔记11:ListView篇之ListView显示多种类型的条目(item)
ListView可以显示多种类型的条目布局,这里写显示两种布局的情况,其他类似. 1. 这是MainActivity,MainActivity的布局就是一个ListView,太简单了这里就不写了,直接 ...
- 实验教学管理系统 c语言程序代写源码下载
问题描述:实验室基本业务活动包括:实验室.班级信息录入.查询与删除:实验室预定等.试设计一个实验教学管理系统,将上述业务活动借助计算机系统完成. 基本要求: 1.必须存储的信息 (1)实验室信息:编号 ...
- linux编辑器 vi的使用
vi 编辑器的三个模式: 命令模式 开始就是命令模式 insert模式 i, I, a, A, o,O ,s, S 命令行模式 : i 在当前位置进入Insert模式 I 在行的头部进入Inser ...