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

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

解法:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 100010;
  4. const int maxm = 200010;
  5. struct edge{
  6. int u,v,w;
  7. edge(){}
  8. bool operator<(const edge &rhs) const{
  9. return w > rhs.w;
  10. }
  11. }edge[maxm];
  12. int V,E;
  13. namespace DSU{
  14. int fa[maxn];
  15. void init(){
  16. for(int i=1; i<maxn; i++) fa[i] = i;
  17. }
  18. int find_set(int x){
  19. if(x==fa[x]) return x;
  20. else return fa[x] = find_set(fa[x]);
  21. }
  22. bool union_set(int x, int y){
  23. x = find_set(x);
  24. y = find_set(y);
  25. if(x!=y){
  26. fa[x] = y;
  27. return 1;
  28. }
  29. return 0;
  30. }
  31. }
  32. using namespace DSU;
  33. int main()
  34. {
  35. while(~scanf("%d %d", &V,&E))
  36. {
  37. init();
  38. for(int i=0; i<V; i++){
  39. int x,y;
  40. scanf("%d %d", &x,&y);
  41. }
  42. long long ans = 0;
  43. for(int i=0; i<E; i++){
  44. scanf("%d %d %d", &edge[i].u, &edge[i].v, &edge[i].w);
  45. ans += edge[i].w;
  46. }
  47. sort(edge, edge+E);
  48. int cnt = 0;
  49. for(int i=0; i<E; i++){
  50. if(union_set(edge[i].u, edge[i].v)){
  51. ans -= edge[i].w;
  52. ++cnt;
  53. }
  54. }
  55. printf("%d %lld\n", E-cnt, ans);
  56. }
  57. return 0;
  58. }

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. Python基础数据类型题

    Python基础数据类型 题考试时间:三个小时 满分100分(80分以上包含80分及格)1,简述变量命名规范(3分) 1.必须是字母,数字,下划线的任意组合. 2.不能是数字开头 3.不能是pytho ...

  2. javascript如何封装函数

    通常写js组件开发的,都会用到匿名函数的写法去封装一个对象,与外界形成一个闭包的作用域.封装,全天下漫天遍野的封装,JQuery,EXT和Prototype.js封装的是javascript,jQue ...

  3. [一]SpringBoot 之 HelloWorld

    (1)新建一个Maven Java工程 (2)在pom.xml文件中添加Spring BootMaven依赖 2.1在pom.xml中引入spring-boot-start-parent spring ...

  4. Luogu4897 【模板】最小割树

    没事干写一发模板. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib& ...

  5. Golang基础(一)

    1. 变量声明与赋值 // var.go package main import "fmt" var a string var b bool var c string = &quo ...

  6. 测试开发面试的Linux面试题总结之二:常用命令

    (1)Linux的文件系统目录配置要遵循FHS规范,规范定义的两级目录规范如下:        /home  每个账号在该目录下都有一个文件夹,进行数据的管理        /usr 有点像windo ...

  7. 使用Java解析XML文件或XML字符串的例子

    转: 使用Java解析XML文件或XML字符串的例子 2017年09月16日 11:36:18 inter_peng 阅读数:4561 标签: JavaXML-Parserdom4j 更多 个人分类: ...

  8. 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 ...

  9. python学习(九) 网络编程学习--简易网站服务器

    python `网络编程`和其他语言都是一样的,服务器这块步骤为:`1. 创建套接字``2. 绑定地址``3. 监听该描述符的所有请求``4. 有新的请求到了调用accept处理请求` Python ...

  10. 在xadmin中自定义内容的变量及优化汇总

    在网上找了很多有关xadmin的内容,发现都不太全 ,找到一篇总结不错的 http://www.lybbn.cn/data/bbsdatas.php?lybbs=62 1.list_display 指 ...