题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6187

题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费。

解法:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxm = 200010;
struct edge{
int u,v,w;
edge(){}
bool operator<(const edge &rhs) const{
return w > rhs.w;
}
}edge[maxm];
int V,E;
namespace DSU{
int fa[maxn];
void init(){
for(int i=1; i<maxn; i++) fa[i] = i;
}
int find_set(int x){
if(x==fa[x]) return x;
else return fa[x] = find_set(fa[x]);
}
bool union_set(int x, int y){
x = find_set(x);
y = find_set(y);
if(x!=y){
fa[x] = y;
return 1;
}
return 0;
}
}
using namespace DSU;
int main()
{
while(~scanf("%d %d", &V,&E))
{
init();
for(int i=0; i<V; i++){
int x,y;
scanf("%d %d", &x,&y);
}
long long ans = 0;
for(int i=0; i<E; i++){
scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].w);
ans += edge[i].w;
}
sort(edge, edge+E);
int cnt = 0;
for(int i=0; i<E; i++){
if(union_set(edge[i].u, edge[i].v)){
ans -= edge[i].w;
++cnt;
}
}
printf("%d %lld\n", E-cnt, ans);
}
return 0;
}

HDU 6187 Destroy Walls (对偶图最小生成树)的更多相关文章

  1. HDU 6187 Destroy Walls (思维,最大生成树)

    HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...

  2. HDU 6187 Destroy Walls

    Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the ...

  3. HDU - 6187 (最大生成树) 最小生成树

    Destroy Walls Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) ...

  4. HDU 5723 Abandoned country (最小生成树 + dfs)

    Abandoned country 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned coun ...

  5. hdu 4940 Destroy Transportation system(水过)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4940 Destroy Transportation system Time Limit: 2000/1 ...

  6. HDU 5723 Abandoned country(最小生成树 + 树形DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5723 [题目大意] n座城市,m条路径,求解: 1.最短的路径和,使得n座城市之间直接或者间接连通 ...

  7. Hdu 1301 Jungle Roads (最小生成树)

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题: 我这里采用了Kruskal算法,当然用Prim算法也 ...

  8. Qin Shi Huang's National Road System HDU - 4081(树形dp+最小生成树)

    Qin Shi Huang's National Road System HDU - 4081 感觉这道题和hdu4756很像... 求最小生成树里面删去一边E1 再加一边E2 求该边两顶点权值和除以 ...

  9. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

随机推荐

  1. BZOJ 1212 L语言(DP+字典树)

    求能被理解的最长前缀. 很显然的dp.令dp[i]=true,表示前缀i能理解.否则不能理解.那么dp[i+len]=dp[i]=true,当s[len]能匹配str[i,i+len]. 由于模式串长 ...

  2. Unified Networking Lab 安装使用IOL镜像

    Unified Networking Lab 安装使用IOL镜像 Unified Networking Lab 很久以前,在一个星系远的地方,很远的工程师们为eBay寻找二手路由器来满足家庭实验的需求 ...

  3. Spring Boot系列教程十:Spring boot集成Sentinel Redis

    前言 上一篇文章介绍了spring boot集成单点的redis,然而实际生产环境使用单点的redis风险很高,一旦宕机整个服务将无法使用,这篇文章介绍如何使用基于sentinel的redis高可用方 ...

  4. BZOJ4408 [Fjoi 2016]神秘数 【主席树】

    题目链接 BZOJ4408 题解 假如我们已经求出一个集合所能凑出连续数的最大区间\([1,max]\),那么此时答案为\(max + 1\) 那么我们此时加入一个数\(x\),假若\(x > ...

  5. 洛谷 P1013 进制位 【搜索 + 进制运算】

    题目描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: + L K V E L L K V E K K V E KL V V E KL KK E E ...

  6. 洛谷U14200 Changing 题解 【杨辉三角】

    题目描述 有nnn盏灯环形排列,顺时针依次标号为1⋯n1\cdots n1⋯n.初始时刻为000,初始时刻第iii盏灯的亮灭aia_iai​给定,000表示灭,111表示亮.下一时刻每盏灯的亮灭取决于 ...

  7. String和stringbuffer和stringbuilder的区别

    String 字符串常量 StringBuffer 字符串变量(线程安全) StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主要 ...

  8. 解题:APIO 2015 雅加达的摩天大楼

    题面 分块思想+最短路 发现对于步长小的doge会连出很多边,很容易导致大量的重边,于是对doge们根据步长分块讨论:根据步长建出分层图,然后把步长不超过某个值的doge们连到对应层上的点上,其余的d ...

  9. 相机标定 和 单应性矩阵H

    求解相机参数的过程就称之为相机标定. 1.相机模型中的四个平面坐标系: 1.1图像像素坐标系(u,v) 以像素为单位,是以图像的左上方为原点的图像坐标系: 1.2图像物理坐标系(也叫像平面坐标系)(x ...

  10. ACE服务端编程4:ACE跨平台之运行时初始化和关闭

    参考APG里的说法:平台差异及不兼容性的一个特别的方面,是对象的运行时初始化和程序关闭时这些对象的相应析构. ACE为了明确管理对象的清理,定义了ACE_Object_Manager类,这个类不仅涉及 ...