题目链接: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 1216 操作系统(堆)

    用堆模拟题目中的操作即可. # include <cstdio> # include <cstring> # include <cstdlib> # include ...

  2. CodeForces 860D Wizard's Tour

    题意 给出一张无向图,要求找出尽量多的长度为2的不同路径(边不可以重复使用,点可以重复使用) 分析 yzy:这是原题 http://www.lydsy.com/JudgeOnline/problem. ...

  3. 【bzoj3456】城市规划 容斥原理+NTT+多项式求逆

    题目描述 求出n个点的简单(无重边无自环)无向连通图数目mod 1004535809(479 * 2 ^ 21 + 1). 输入 仅一行一个整数n(<=130000) 输出 仅一行一个整数, 为 ...

  4. 【读书笔记】《HTTP权威指南》:Web Hosting

    一.概述 从零开始构建一个真正意义的网站需要做很多事情,包括购买计算机硬件.建造机房.注册域名.购买网络带宽.开发Web服务器软件.管理网站内容等等.在互联网发展的早期,构建网站的这一系列动作通常都是 ...

  5. 专题训练之区间DP

    例题:以下例题部分的内容来自https://blog.csdn.net/my_sunshine26/article/details/77141398 一.石子合并问题 1.(NYOJ737)http: ...

  6. cmakelist 定义字符串,替换到脚本中。

    cmake_minimum_required(VERSION 2.6 FATAL_ERROR) cmake_policy(VERSION 2.6) # . Project Name project(s ...

  7. Codeforces 939.E Maximize!

    E. Maximize! time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  8. 把一个文件中所有文件名或者文件路径读取到一个txt文件,然后在matlab中读取

    链接: http://blog.csdn.net/dreamgchuan/article/details/51113295 dir /on/b/s  这个读取的是这样的格式:

  9. C++并发编程 等待与唤醒

    C++并发编程 等待与唤醒 条件变量 条件变量, 包括(std::condition_variable 和 std::condition_variable_any) 定义在 condition_var ...

  10. ZABBIX 3.0 配置监控MYSQL性能【OK】

    Zabbix3.0自带了MySQL插件来监控mysql数据库的模板,只需要配置好agent客户端,然后在web端给主机增加模板就行了. 参考:http://www.cnblogs.com/keving ...