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个点 ...
随机推荐
- Python基础数据类型题
Python基础数据类型 题考试时间:三个小时 满分100分(80分以上包含80分及格)1,简述变量命名规范(3分) 1.必须是字母,数字,下划线的任意组合. 2.不能是数字开头 3.不能是pytho ...
- javascript如何封装函数
通常写js组件开发的,都会用到匿名函数的写法去封装一个对象,与外界形成一个闭包的作用域.封装,全天下漫天遍野的封装,JQuery,EXT和Prototype.js封装的是javascript,jQue ...
- [一]SpringBoot 之 HelloWorld
(1)新建一个Maven Java工程 (2)在pom.xml文件中添加Spring BootMaven依赖 2.1在pom.xml中引入spring-boot-start-parent spring ...
- Luogu4897 【模板】最小割树
没事干写一发模板. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib& ...
- Golang基础(一)
1. 变量声明与赋值 // var.go package main import "fmt" var a string var b bool var c string = &quo ...
- 测试开发面试的Linux面试题总结之二:常用命令
(1)Linux的文件系统目录配置要遵循FHS规范,规范定义的两级目录规范如下: /home 每个账号在该目录下都有一个文件夹,进行数据的管理 /usr 有点像windo ...
- 使用Java解析XML文件或XML字符串的例子
转: 使用Java解析XML文件或XML字符串的例子 2017年09月16日 11:36:18 inter_peng 阅读数:4561 标签: JavaXML-Parserdom4j 更多 个人分类: ...
- Codeforces Round #299 (Div. 2)A B C 水 dfs 二分
A. Tavas and Nafas time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- python学习(九) 网络编程学习--简易网站服务器
python `网络编程`和其他语言都是一样的,服务器这块步骤为:`1. 创建套接字``2. 绑定地址``3. 监听该描述符的所有请求``4. 有新的请求到了调用accept处理请求` Python ...
- 在xadmin中自定义内容的变量及优化汇总
在网上找了很多有关xadmin的内容,发现都不太全 ,找到一篇总结不错的 http://www.lybbn.cn/data/bbsdatas.php?lybbs=62 1.list_display 指 ...