一、题目

 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. 解决宝塔面板没有命令行问题 && 查看宝塔面板项目环境

    # 宝塔面板没有命令行,无法查看错误输出 利用ssh.比如xshell,MObaxtern .输入ip,username,password就可以进入服务器的命令行. # 查看项目的环境 服务器默认的p ...

  2. 手工数据结构系列-C语言模拟队列 hdu1276

    #include <stdio.h> #include <stdlib.h> #define init_size 1000 typedef struct { int head, ...

  3. git branch & git remote branch

    git branch & git remote branch $ git branch -h usage: git branch [<options>] [-r | -a] [-- ...

  4. Jamstack Conf 2020

    Jamstack Conf 2020 Jamstack Conf Virtual https://jamstackconf.com/virtual/ Conf Schedule https://jam ...

  5. how to config custom process.env in node.js

    how to config custom process.env in node.js process.env APP_ENV NODE_ENV https://nodejs.org/api/proc ...

  6. JavaScript 如何使用 setTimeout 实现 setInterval

    JavaScript 如何使用 setTimeout 实现 setInterval website multi content page setIntervalSimulator "use ...

  7. App Store Previewer

    App Store Previewer App Store 模拟器 https://www.storepreviewer.com/ xgqfrms 2012-2020 www.cnblogs.com ...

  8. macOS 屏幕共享, 远程协助

    macOS 屏幕共享, 远程协助 Screen Sharing App 隐藏 app bug command + space 搜索 https://macflow.net/p/397.html Tea ...

  9. 教你玩转CSS border(边框)

    边框样式 边框样式属性指定要显示什么样的边界. border-style属性用来定义边框的样式 border-style的值 代码演示: <!DOCTYPE html> <html ...

  10. 创建gitHub账户并配置秘钥

    1. 登录注册地址 https://github.com/ 2.点击注册 Sign up 3.输入邮箱 密码 进行注册 4.注册成功后,登录邮箱验证 .然后通过邮箱和密码登录gitHub.设置 set ...