Destroy Walls

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 377    Accepted Submission(s): 166

Problem Description

Long times ago, there are beautiful historic walls in the city. These walls divide the city into many parts of area.

Since it was not convenient, the new king wants to destroy some of these walls, so he can arrive anywhere from his castle. We assume that his castle locates at (0.6∗2√,0.6∗3√).

There are n towers in the city, which numbered from 1 to n. The ith's location is (xi,yi). Also, there are m walls connecting the towers. Specifically, the ith wall connects the tower ui and the tower vi(including the endpoint). The cost of destroying the ith wall is wi.

Now the king asks you to help him to divide the city. Firstly, the king wants to destroy as less walls as possible, and in addition, he wants to make the cost least.

The walls only intersect at the endpoint. It is guaranteed that no walls connects the same tower and no 2 walls connects the same pair of towers. Thait is to say, the given graph formed by the walls and towers doesn't contain any multiple edges or self-loops.

Initially, you should tell the king how many walls he should destroy at least to achieve his goal, and the minimal cost under this condition.

 

Input

There are several test cases.

For each test case:

The first line contains 2 integer n, m.

Then next n lines describe the coordinates of the points.

Each line contains 2 integers xi,yi.

Then m lines follow, the ith line contains 3 integers ui,vi,wi

|xi|,|yi|≤105

3≤n≤100000,1≤m≤200000

1≤ui,vi≤n,ui≠vi,0≤wi≤10000

 

Output

For each test case outout one line with 2 integers sperate by a space, indicate how many walls the king should destroy at least to achieve his goal, and the minimal cost under this condition. 
 

Sample Input

4 4
-1 -1
-1 1
1 1
1 -1
1 2 1
2 3 2
3 4 1
4 1 2
 

Sample Output

1 1
 

Source

 

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6242 6241 6240 6239 6238 
 
题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费。
思路:首先可以发现题目就是要求一个平面图对偶图的最小生成树。 
     根据欧拉公式我们可以知道对于一个有k个连通分量的平面图的区域数r=E−V+k+1。
     那么对偶图生成树的边数为r−1=E−V+k,这些边也就是要删除的原图中的边,那么要留下的边数就是V−k这刚好就是原图每个连通分量生成树的边数之和。
     考虑保留原图每个连通分量的生成树,显然满足要求。
     题目要求花费最小,也就是留下的边权值最大,那么我们直接对每个连通分量求最大生成树即可,删除的边数就是总边数减去生成树的边数和,最小花费就是全部边的花费减去最大生成树的花费。
  1. //2017-11-16
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int N = ;
  10. const int M = ;
  11.  
  12. namespace DSU{
  13. int fa[N];
  14. void init(){
  15. for(int i = ; i < N; i++)fa[i] = i;
  16. }
  17. int getfa(int x){
  18. return fa[x] = x == fa[x] ? x : getfa(fa[x]);
  19. }
  20. void merge(int a, int b){
  21. int af = getfa(a);
  22. int bf = getfa(b);
  23. if(af != bf){
  24. fa[bf] = af;
  25. }
  26. }
  27. }
  28.  
  29. struct Edge{
  30. int u, v, w;
  31. bool operator< (const Edge e) const {
  32. return w > e.w;
  33. }
  34. }edge[M];
  35.  
  36. int main()
  37. {
  38. freopen("input.txt", "r", stdin);
  39. int n, m, x, y;
  40. while(~scanf("%d%d", &n, &m)){
  41. for(int i = ; i < n; i++)
  42. scanf("%d%d", &x, &y);
  43. int ans = ;
  44. for(int i = ; i < m; i++){
  45. scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
  46. ans += edge[i].w;
  47. }
  48. DSU::init();
  49. sort(edge, edge+m);
  50. int cnt = ;
  51. for(int i = ; i < m; i++){
  52. int u = edge[i].u;
  53. int v = edge[i].v;
  54. if(DSU::getfa(u) != DSU::getfa(v)){
  55. ans -= edge[i].w;
  56. DSU::merge(u, v);
  57. cnt++;
  58. }
  59. }
  60. printf("%d %d\n", m-cnt, ans);
  61. }
  62.  
  63. return ;
  64. }

HDU6187(对偶图生成树)的更多相关文章

  1. bzoj 4541: [Hnoi2016]矿区【平面图转对偶图+生成树】

    首先平面图转对偶图,大概思路是每条边存正反,每个点存出边按极角排序,然后找每条边在它到达点的出边中极角排序的下一个,这样一定是这条边所属最小多边形的临边,然后根据next边找出所有多边形,用三角剖分计 ...

  2. HDU-6187.DestroyWalls(最大生成树)

    好吧这个题没什么可说的,有点.... 一开始还和一位大佬在讨论,会不会有多余的边,后面看了题发现没有多于的边和自环,所以之间一波最大生成树把最大的边去掉,把最小的边推倒就行了. #include &l ...

  3. BZOJ4541 HNOI2016矿区(平面图转对偶图)

    考虑先将平面图转化为对偶图.具体地,将无向边拆成两条有向边.每次考虑找到包围一个区域的所有边.对当前考虑的边,找到该边的反向边在该边终点的出边集中,按极角序排序的后继,这条后继边也是包围该区域的边.这 ...

  4. LOJ#2052. 「HNOI2016」矿区(平面图转对偶图)

    题面 传送门 题解 总算会平面图转对偶图了-- 首先我们把无向边拆成两条单向边,这样的话每条边都属于一个面.然后把以每一个点为起点的边按极角排序,那么对于一条边\((u,v)\),我们在所有以\(v\ ...

  5. 图的生成树(森林)(克鲁斯卡尔Kruskal算法和普里姆Prim算法)、以及并查集的使用

    图的连通性问题:无向图的连通分量和生成树,所有顶点均由边连接在一起,但不存在回路的图. 设图 G=(V, E) 是个连通图,当从图任一顶点出发遍历图G 时,将边集 E(G) 分成两个集合 T(G) 和 ...

  6. bzoj 1001狼抓兔子(对偶图+最短路)最大流

    推荐文章:<浅析最大最小定理在信息学竞赛中的应用>--周冬 题目 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还 ...

  7. BZOJ1001: [BeiJing2006]狼抓兔子 [最小割 | 对偶图+spfa]

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 19528  Solved: 4818[Submit][ ...

  8. NOIP 2013 货车运输 最大生成树加DFS巧妙AC

    #include<set> #include<map> #include<cmath> #include<queue> #include<stac ...

  9. luogu p2330[SCOI05] 繁忙的都市——瓶颈生成树

    P2330 05四川 繁忙的都市 题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道 ...

随机推荐

  1. 包建强的培训课程(14):Android与ReactNative

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  2. xampp运行MySQL shutdown unexpectedly解决方案

    昨天晚上自己的网站突然打不开了,以为被人黑了.想想不应该啊,这小站不会有人关注的,于是登录服务器看了下,发现是Mysql打不开了 很奇怪,因为今天白天还是可以打开的,下班后也没有碰过服务器 首先看看是 ...

  3. Git使用详细教程(1):工作区、暂存区、本地仓库、远程仓库

    之前的写过一篇如何在服务器上搭建Git服务Git服务器搭建,接下来的一段时间,我将详细的讲解Git的使用.看如下一张图片,本篇主要理解一些基本概念. 图中几个名词的意思如下: workspace: 工 ...

  4. Java 实现文件压缩工具类

    package com.wdxc.util; import java.io.BufferedInputStream; import java.io.File; import java.io.FileI ...

  5. 移动端video标签默认置顶的解决方案

    概述 在移动端上面,比如说微信上面打开一个页面,如果有video标签的话,常常会出现video标签默认置顶的情况,一般的解决方案是在不需要看见它的时候给它加一个display:none进行隐藏.今天在 ...

  6. java项目引用证书文件(微信支付的p12文件)

    1. 绝对路径: // windows: public static String PATH1 = "E:\\project27_app_wuyoujie\\apiclient_cert.p ...

  7. 数据库语句收藏(MySQL)

    概览 => MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性. =>关键字不区分大小写 => S ...

  8. Spring Boot 返回 XML 数据,一分钟搞定!

    Spring Boot 返回 XML 数据,前提必须已经搭建了 Spring Boot 项目,所以这一块代码就不贴了,可以点击查看之前分享的 Spring Boot 返回 JSON 数据,一分钟搞定! ...

  9. python高级-面向对象特性(12)

    一.继承的概念 在现实生活中,继承一般指的是子女继承父辈的财产,在程序中,继承描述的是事物之间的所属关系,例如猫和狗都属于动物,程序中便可以描述为猫和狗继承自动物:同理,波斯猫和巴厘猫都继承自猫,而沙 ...

  10. golang实现参数可变的技巧

    Go 使用默认参数的技巧 Functional Options Pattern in Go golang中没有函数默认参数的设计,因此需要些特别的技巧来实现. 假如我们需要订购一批电脑,其中电脑配置c ...