题意:

求1到n路径上最大的最小值。

原因:样例输入

1

3 3

1 2 3

1 3 4

2 3 5

1-2最多可以运输3,2-3可最多以运输5,但是2的来源只有3,所以路径1-2-3上能运输的量为3

1-3可以运输4,所以结果就是4。

可以很明显的看出一条路径上能够运输的最大值与该路径上最小的边相等,所以只需求出最大的最小值即可。

最大生成树一定是一棵瓶颈树,由瓶颈树的性质可知,最小边一定最大。

按权值从大到小排序,跑一遍Kruskal求最大生成树记录最小值,当1与n联通时,即利用并查集判断find(1)==find(n)时返回此时最小值即可。

注意输出格式,每一个例子后都有一个空行(包括最后一个例子)。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std; const int maxn = + ;
const int inf = 0x3f3f3f3f;
int n, m, t, pre[maxn];
struct edge{
int u, v, w;
bool operator < ( const edge &a )const{
return w>a.w;
}
} ed[maxn*maxn];
inline int find( int x ){
return pre[x]==x ? x:pre[x] = find(pre[x]);
} inline int min( int a, int b ){
return a<b ?a:b;
} inline int kru(){
sort( ed, ed+m );
int res = inf;
for( int i=; i<m; i++ ){
int fx = find(ed[i].u);
int fy = find(ed[i].v);
if( fx!=fy ){
pre[fx] = fy;
res = min( res, ed[i].w );
if( find()==find(n) ) break;  //此处其实不用求min 只需当find(i)==find(n)时让res = ed[i].w 然后break即可
}
}
return res;
} int main(){
scanf("%d", &t);
for( int k=; k<=t; k++ ){
scanf("%d%d", &n, &m);
for( int i=; i<=n; i++ ) pre[i] = i;
for( int i=; i<m; i++ )
scanf("%d%d%d",&ed[i].u, &ed[i].v, &ed[i].w);
int ans = kru();
printf("Scenario #%d:\n", k);
printf("%d\n\n", ans);
} return ;
}

POJ 1797 Heavy Transportation(Kruskal灵活使用)(瓶颈树)的更多相关文章

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

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

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

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

  3. POJ.1797 Heavy Transportation (Dijkstra变形)

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

  4. POJ 1797 Heavy Transportation

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

  5. POJ 1797 Heavy Transportation SPFA变形

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

  6. POJ 1797 Heavy Transportation (Dijkstra变形)

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

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

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

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

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

  9. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

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

随机推荐

  1. Xamarin Assets文件读取

    在Assets文件夹中添加nlog.config文件,在属性中将Build Action设置为AndroidAsset var steam = Assets.Open("nlog.confi ...

  2. FLINK-11738

    caused by: akka.pattern.asktimeoutexception: ask timed out on flink Caused by: akka.pattern.AskTimeo ...

  3. UE4 Animation]IK Related

    转自:https://dawnarc.com/2018/05/ue4animationik-related/ Examples 工程1 在油管上看到一个UE4 IK动画的demo工程示例 该示例作者的 ...

  4. c# 字符串递归截取

    private void button1_Click_1(object sender, EventArgs e) { string ex = neirong.Text; List<string& ...

  5. POJ 3624 Charm Bracelet(01背包模板题)

    题目链接 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52318   Accepted: 21912 Descriptio ...

  6. netcore 步骤

    1.创建工程目录 d:\project 2.进入目录,创建解决方案 dotnet new sln 3.确定开发版本 dotnet --list-sdks //列出sdk版本 dotnet new gl ...

  7. js中常见字符串类型操作方法(2)

    toLowerCase(),toLocalLowerCase(),toUpperCase(),toLocaleUpperCase() var stringValue = "hello wor ...

  8. Oracle各种连接函数总结

    1.前言 Oracle可用连接函数会介绍以下几个 Oracle列转行函数 Listagg() strcat() wmsys.wm_concat() 2.Oracle列转行函数 Listagg() 2. ...

  9. go ---变量数据结构调试利器 go-spew

    我们在使用Golang(Go语言)开发的过程中,会通过经常通过调试的方式查找问题的原因,解决问题,尤其是当遇到一个很棘手的问题的时候,就需要知道一段代码在执行的过程中,其上下文的变量对应的数据,以便进 ...

  10. ElasticSearch 调优

    来源:http://tinyurl.com/y4gnzbje 第一部分:调优索引速度 第二部分-调优搜索速度 英文原文:https://www.elastic.co/guide/en/elastics ...