一、题目

 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. Eazfuscator.NET(.net混淆工具)

    软件功能 调试支持: 在你的程序集被Eazfuscator.NET混淆后,它不会成为不可调试混乱的砖块.你总是可以得到一个行号,出现未处理的异常,查看可读的堆栈跟踪,甚至附加调试器来遍历你的模糊代码. ...

  2. 如何加入VNT Hubble主网

    环境:Ubuntu20.04 (但以下方法应该只要不是过于老旧的Ubuntu,都行得通) 从源码安装go-vnt 安装Go编译器(版本大于1.9)和C编译器 安装C编译器GCC[1] sudo apt ...

  3. 833A The Meaningless Game

    A. The Meaningless Game time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. 101道Numpy、Pandas练习题

    无论是数据分析还是机器学习,数据的预处理必不可少. 其中最常用.最基础的Python库非numpy和pandas莫属,很多初学者可能看了很多教程,但是很快就把用法忘光了. 光看不练假把式,今天向大家推 ...

  5. JavaScript 的 7 种设计模式

    原文地址:Understanding Design Patterns in JavaScript 原文作者:Sukhjinder Arora 译者:HelloGitHub-Robert 当启动一个新的 ...

  6. npm install 原理

    npm install 原理 https://docs.npmjs.com/about-npm/ npm consists of three distinct components: the webs ...

  7. ES-Next classes static properties

    ES-Next classes static properties https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/ ...

  8. NGK生态之星空计划启动在即,稀有VAST高兑换比带来高价值!

    NGK生态之星空计划启动在即,为了感谢NGK布道者的支持,NGK官方将全力辅助算力市场,开展全新的星空计划,并发行星空币SPC,空投给算力持有者进行额外奖励. 至此,SPC已经顺利完成2轮空投,也初步 ...

  9. Renice INC:解密干型葡萄酒

    市场上,干型葡萄酒往往对比甜型葡萄酒(如甜红.甜白)受到更多葡萄酒爱好者的青睐.在葡萄酒界,大部分的红葡萄酒和白葡萄酒也都是干型的,而且它们的口感往往各有特色,并非千篇一律.今天,就跟随Renice ...

  10. 聊聊CacheLine

    本文转载自聊聊CacheLine 导语 文章聊聊缓存一致性协议中我们提到过,缓存里面最小的单位是缓存行/缓存条目,但是缓存中的具体存储结构是什么样的,缓存行中有存放的是什么?在缓存中是如何寻找指定是还 ...