HDU-6187.DestroyWalls(最大生成树)
好吧这个题没什么可说的,有点....
一开始还和一位大佬在讨论,会不会有多余的边,后面看了题发现没有多于的边和自环,所以之间一波最大生成树把最大的边去掉,把最小的边推倒就行了。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + , maxm = + ;
int n, m, ans, head[maxn];
bool vis[maxm];
struct Edge {
int u, v, w;
} edge[maxm]; bool cmp(const Edge &a, const Edge &b) {
return a.w > b.w;
} int Find(int x) {
if(x == head[x]) return x;
else return head[x] = Find(head[x]);
} int main() {
int x, y;
while(~scanf("%d %d", &n, &m)) {
ans = ;
memset(vis, false, sizeof vis);
for(int i = ; i <= n; i ++) {
scanf("%d %d", &x, &y);
head[i] = i;
}
for(int i = ; i < m; i ++) {
scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].w);
}
sort(edge, edge + m, cmp);
int cnt = , num = ;
for(int i = ; i < m; i ++) {
int fx = Find(edge[i].u), fy = Find(edge[i].v);
if(fx != fy) {
cnt ++;
head[fx] = fy;
vis[i] = true;
}
if(cnt == n - ) break;
}
for(int i = ; i < m; i ++) {
if(!vis[i]) {
ans += edge[i].w;
num ++;
}
}
printf("%d %d\n", num, ans);
}
return ;
}
HDU-6187.DestroyWalls(最大生成树)的更多相关文章
- HDU 6187 Destroy Walls (思维,最大生成树)
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...
- HDU - 6187 (最大生成树) 最小生成树
Destroy Walls Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
- HDU 6187 Destroy Walls (对偶图最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6187 题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一 ...
- HDU 4786 Fibonacci Tree(生成树,YY乱搞)
http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...
- hdu 3367 Pseudoforest(最大生成树)
Pseudoforest Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- HDU 6187 Destroy Walls
Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the ...
- hdu 3367(与最大生成树无关。无关。无关。重要的事情说三遍+kruskal变形)
Pseudoforest Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 4786 Fibonacci Tree 生成树
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4786 题意:有N个节点(1 <= N <= 10^5),M条边(0 <= M <= ...
- hdu 3367 Pseudoforest 最大生成树★
#include <cstdio> #include <cstring> #include <vector> #include <algorithm> ...
随机推荐
- ZROI 19.07.28 序列数据结构/jk
写在前面 dls:"我不会数据结构,但是APIO的数据结构场我写了,还是蛮简单的." T1 CF643G Sol: 有一个\(O(n\log^2n)\)的做法:假设将区间排好序,取 ...
- MySQL集群安装与配置
MySQL集群安装与配置 文章目录 [隐藏] 一.mysql集群安装 二.节点配置 三.首次启动节点 四.测试服务是否正常 五.安全关闭和重启 MySQL Cluster 是 MySQL 适合于分 ...
- linux软件操作
操作 命令 ubuntu 源操作 源配置 https://www.cnblogs.com/wenlin-gk/p/11146228.html 源更新 sudo apt-get update 查看源中包 ...
- 【GDOI2014模拟】网格
题目 某城市的街道呈网格状,左下角坐标为A(0, 0),右上角坐标为B(n, m),其中n >= m.现在从A(0, 0)点出发,只能沿着街道向正右方或者正上方行走,且不能经过图示中直线左上方的 ...
- linux运维、架构之路-jumpserver
一.jumpserver介绍 是一款由python编写开源的跳板机(堡垒机)系统,实现了跳板机应有的功能.基于ssh协议来管理,客户端无需安装agent. 特点: 完全开源,GPL ...
- layer.confirm
layer.confirm('确定不选择花车?', { title: false, btn: ['确定','取消'] //按钮 }, function(ind){ layer.close(ind); ...
- webstorm主题更换和webstorm汉化
主题更换方式一 主题类型:*.jar 在webstorm程序中选择 : 菜单栏 File -> Setting ->Import Settings 选中下载的.jar文件 主题更换方式二 ...
- Laya layout算法
/** * <p>重置对象的 <code>X</code> 轴(水平方向)布局.</p> * @private */ public function r ...
- Leetcode 11. Container With Most Water(逼近法)
11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...
- Packet Transactions: High-level Programming for Line-Rate Switches
Name of article:Packet Transactions: High-level Programming for Line-Rate Switches Origin of the art ...