HDU 6187 Destroy Walls (对偶图最小生成树)
题目链接: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 (对偶图最小生成树)的更多相关文章
- HDU 6187 Destroy Walls (思维,最大生成树)
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...
- HDU 6187 Destroy Walls
Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the ...
- HDU - 6187 (最大生成树) 最小生成树
Destroy Walls Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others) ...
- HDU 5723 Abandoned country (最小生成树 + dfs)
Abandoned country 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5723 Description An abandoned coun ...
- hdu 4940 Destroy Transportation system(水过)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4940 Destroy Transportation system Time Limit: 2000/1 ...
- HDU 5723 Abandoned country(最小生成树 + 树形DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5723 [题目大意] n座城市,m条路径,求解: 1.最短的路径和,使得n座城市之间直接或者间接连通 ...
- Hdu 1301 Jungle Roads (最小生成树)
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题: 我这里采用了Kruskal算法,当然用Prim算法也 ...
- Qin Shi Huang's National Road System HDU - 4081(树形dp+最小生成树)
Qin Shi Huang's National Road System HDU - 4081 感觉这道题和hdu4756很像... 求最小生成树里面删去一边E1 再加一边E2 求该边两顶点权值和除以 ...
- HDU 1162 Eddy's picture (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
随机推荐
- 【bzoj2351】[BeiJing2011]Matrix 二维Hash
题目描述 给定一个M行N列的01矩阵,以及Q个A行B列的01矩阵,你需要求出这Q个矩阵哪些在原矩阵中出现过.所谓01矩阵,就是矩阵中所有元素不是0就是1. 输入 输入文件的第一行为M.N.A.B,参见 ...
- macvtap介绍
macvtap介绍 传统的linux网络虚拟化技术采用的是tap+bridge方式,将虚拟机连接到虚拟的tap网卡,然后将tap网卡加入到bridge.bridge相当于用软件实现的交换机,这种解决方 ...
- NOIP2003 传染病控制 【搜索 + 卡时】
题目背景 近来,一种新的传染病肆虐全球.蓬莱国也发现了零星感染者,为防止该病在蓬莱国大范围流行,该国政府决定不惜一切代价控制传染病的蔓延.不幸的是,由于人们尚未完全认识这种传染病,难以准确判别病毒携带 ...
- spark(三)spark sql
一.DataFrame 1.DataFrame是组织成命名列的数据的分布式集合,类似于关系型数据库的一张表,如果没有列名就等于RDD,如果有列名,就是DataFrames DataFrames可以从各 ...
- bzoj4165: 矩阵(堆+hash)
求第k大用堆维护最值并出堆的时候扩展的经典题... 因为只有正数,所以一个矩阵的权值肯定比它的任意子矩阵的权值大,那么一开始把所有满足条件的最小矩阵加进堆里,弹出的时候上下左右扩展一行加进堆,用has ...
- uoj 36 玛里苟斯
[清华集训2014]玛里苟斯 - 题目 - Universal Online Judge k=1,2,3,4,5各占20pts是提示 应当分开考虑 k=1 拆位,如果第i位有1,则有1/2的概率xor ...
- Win8Metro(C#)数字图像处理--2.40二值图像轮廓提取
http://dongtingyueh.blog.163.com/blog/static/4619453201271481335630/ [函数名称] 二值图像轮廓提取 Contour ...
- Spring MVC @ModelAttribute详解
被@ModelAttribute注释的方法会在此controller每个方法执行前被执行,因此对于一个controller映射多个URL的用法来说,要谨慎使用. 我们编写控制器代码时,会将保存方法独立 ...
- Overlaying GPS Coordinates for Camera Crosshairs
Hey Guys! I am working on a project to allow us to implement GPS coordinates for the location of the ...
- lightoj 1020 (博弈水题)
lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...