一、题目

 POJ1797

二、分析

 题意就是让你找到从1到n的一条路,由于边的最大称重限制,你需要确定限制的最小值,也就是能运输的最大值。

 可以结合最小生成树想,利用并查集,然后不断更新答案即可,需要注意的是题意是1到n走到就可以了,并不需要走到每个点,所以不是完整的最大生成树,所以当1与n共父节点时直接返回结果即可。

三、AC代码

 1 #include <cstdio>
2 #include <iostream>
3 #include <algorithm>
4 #include <cstring>
5
6 using namespace std;
7 const int MAXN = 1e3 + 14;
8
9 struct edge
10 {
11 int from, to, cost;
12 bool operator < (const edge &e)
13 {
14 return cost > e.cost;
15 }
16 }E[MAXN*MAXN];
17 int m, n;
18 int par[MAXN];
19
20 int Find(int x)
21 {
22 return par[x] == x ? x : par[x] = Find(par[x]);
23 }
24
25 int Kruskal()
26 {
27 int Ans = 1e7;
28 for(int i = 1; i <= n; i++)
29 par[i] = i;
30 for(int i = 0; i < m; i++)
31 {
32 int a = E[i].from, b = E[i].to;
33 int fa = Find(a), fb = Find(b);
34 if(fa == fb)
35 {
36 continue;
37 }
38 else
39 {
40 Ans = min(Ans, E[i].cost);
41 par[fa] = fb;
42 }
43 if(Find(1) == Find(n))
44 return Ans;
45
46 }
47 return Ans;
48 }
49
50 int main()
51 {
52 //freopen("in.txt", "r", stdin);
53 int T, Case = 0;
54 scanf("%d", &T);
55 while(T--)
56 {
57 if(Case)
58 puts("");
59 scanf("%d%d", &n, &m);
60 for(int i = 0; i < m; i++)
61 scanf("%d%d%d", &E[i].from, &E[i].to, &E[i].cost);
62 sort(E, E + m);
63 printf("Scenario #%d:\n%d\n", ++Case, Kruskal());
64 }
65 return 0;
66 }

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. [poj1797]Heavy Transportation<最大生成树prim&kruskal>

    题目链接:http://poj.org/problem?id=1797 题意:给定n个点,m条边,每条边连接两点切有权值.求点1到点n的路径的上的最小边的值最大... 翻别人博客找到的题,方法挺多的, ...

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

    题目链接:http://poj.org/problem?id=1797 Description Background Hugo Heavy is happy. After the breakdown ...

  4. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

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

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

  7. #图# #最大生成树# #kruskal# ----- OpenJudge 799:Heavy Transportation

    OpenJudge 799:Heavy Transportation 总时间限制: 3000ms 内存限制: 65536kB 描述BackgroundHugo Heavy is happy. Afte ...

  8. Heavy Transportation(最短路 + dp)

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

  9. poj 1797 Heavy Transportation(最短路径Dijkdtra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 26968   Accepted: ...

随机推荐

  1. Python-collections模块之defaultdict

    defaultdict defaultdict 是 dict 类型的子类,正如其名,初始化时,可以给key指定默认值,什么意思呢?直接看代码.如果是普通的dict对象,访问一个不存在的key时,会报错 ...

  2. test markdown && 代码高亮

    #include<cstdio> #include<cstring> #include<queue> #include<vector> #include ...

  3. C# 类 (11) - Const

    Const variable 变量 ,值可变的constant 常量,不可变,C# 里关键字是const当我们定义一个常量的时候,需要立马赋值,以后不能再改这个量了我们可以把常量定义在 method ...

  4. 北京网络赛G BOXES 大模拟+BFS

    题目描述 Description There is a strange storehouse in PKU. In this storehouse there are n slots for boxe ...

  5. 利用设置新数据存储结构解决vue中折叠面板双向绑定index引起的问题

    问题背景是,在进行机器性能可视化的前端开发时,使用折叠面板将不同机器的性能图表画到不同的折叠面板上去.而机器的选择利用select下拉选项来筛选. 由于在折叠面板中,通过 如下v-model双向绑定了 ...

  6. u-boot 移植 --->4、Tiny210核心板的DDR初始化下详解

    RAM的原理简单学习 DDR是RAM的一种,RAM常见的类型有SRAM,SDRAM,DDR他们的共同特点是,随机存储意味着读写速度快,掉电后数据丢失,所以常用来存储程序中的变量. SRAM 静态随机存 ...

  7. LWIP再探----内存池管理

    这这里是接上一篇内存池管理部分的,这里如果读者一打开memp.c的话会感觉特别那一理解原作者在干嘛,但是看懂了就明白原作者是怎么巧妙的使用了宏.废话不多说先说了下我分析是一下宏的条件是 前提条件MEM ...

  8. SEO All In One

    SEO All In One website SEO https://www.google.com/search?newwindow=1&safe=active&sxsrf=ALeKk ...

  9. Egg.js 是什么?

    Egg.js 是什么? 阿里巴巴出 Egg.js 为企业级框架和应用而生,我们希望由 Egg.js 孕育出更多上层框架,帮助开发团队和开发人员降低开发和维护成本. 注:Egg.js 缩写为 Egg 设 ...

  10. [转]LINUX下编译c++11的代码

    转载地址: https://blog.csdn.net/lwb102063/article/details/50445201 C++11,(即ISO/IEC 14882:2011),是目前的C++编程 ...