一、题目

 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. VS2010下如何查看类的内存布局

    用VS2010查看类的内存布局,这里用两种方法 (1)MSVC有个隐藏的"/d1"开关,通过这个开关可以查看项目中类的内存布局情况. 修改项目属性,添加"/d1 repo ...

  2. codeforces 869A

    A. The Artful Expedient time limit per test 1 second memory limit per test 256 megabytes input stand ...

  3. IP的地址的划分

    IP地址的划分是计算机网络中很重要的一个知识点,曾经考过三级,但是长时间不用就会忘掉,现在重新将IP的地址划分整理一遍. 首先IP地址的编址方法经历了三个阶段:分类的IP地址.子网的划分.构成超网 我 ...

  4. MQTT 协议 部分细节

    这里不纪录协议文档中大部分通用内容主要记录一下自己比较困惑的细节处理机制.主要有如下几个点: 连接时的具体细节行为? client 在连接到broker时同时指定自己的keepaliveTime和 w ...

  5. Keras 报错: Error when checking target: expected dense_4...

    笔者此处是一个回归任务, 最后一层是: ... pred = Dense(1)(x) 在最后一个Dense层前加上x = Flatten()(x)即可.

  6. 机器学习入门实战——基于knn的airbnb房租预测

    数据读取 import pandas as pd features=['accommodates','bathrooms','bedrooms','beds','price','minimum_nig ...

  7. Pygame 游戏开发 All In One

    Pygame 游戏开发 All In One Pygame Pygame is a library for digital arts, games, music, making, and a comm ...

  8. Web 开发之 HTTP/2 & SPDY & HTTP 1.1 & HTTP 对比分析详解!

    1 https://zh.wikipedia.org/wiki/HTTP/2 HTTP/2 维基百科,自由的百科全书                         HTTP/2(超文本传输协议第2版 ...

  9. JavaScript console.log Questions All In One

    JavaScript console.log Questions All In One "use strict"; /** * * @author xgqfrms * @licen ...

  10. 我眼中的价值币——NGK(下)

    跨链交互方案并不是区块链世界中的一个新课题.自比特币诞生揭开智能合约的序幕之后,跨链交互的需求便产生了.但是,经过十年的发展,市场中的跨链解决方案进展缓慢,究之原因有以下几个方面. 首先,区块链的去中 ...