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这刚好就是原图每个连通分量生成树的边数之和。
     考虑保留原图每个连通分量的生成树,显然满足要求。
     题目要求花费最小,也就是留下的边权值最大,那么我们直接对每个连通分量求最大生成树即可,删除的边数就是总边数减去生成树的边数和,最小花费就是全部边的花费减去最大生成树的花费。
 //2017-11-16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
const int M = ; namespace DSU{
int fa[N];
void init(){
for(int i = ; i < N; i++)fa[i] = i;
}
int getfa(int x){
return fa[x] = x == fa[x] ? x : getfa(fa[x]);
}
void merge(int a, int b){
int af = getfa(a);
int bf = getfa(b);
if(af != bf){
fa[bf] = af;
}
}
} struct Edge{
int u, v, w;
bool operator< (const Edge e) const {
return w > e.w;
}
}edge[M]; int main()
{
freopen("input.txt", "r", stdin);
int n, m, x, y;
while(~scanf("%d%d", &n, &m)){
for(int i = ; i < n; i++)
scanf("%d%d", &x, &y);
int ans = ;
for(int i = ; i < m; i++){
scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
ans += edge[i].w;
}
DSU::init();
sort(edge, edge+m);
int cnt = ;
for(int i = ; i < m; i++){
int u = edge[i].u;
int v = edge[i].v;
if(DSU::getfa(u) != DSU::getfa(v)){
ans -= edge[i].w;
DSU::merge(u, v);
cnt++;
}
}
printf("%d %d\n", m-cnt, ans);
} return ;
}

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. C 线性表的顺序存储实现及插入、删除等操作示例

    一.线性表的定义 线性表(Linear List)是由同一类型元素构成的有序序列的线性结构.线性表中元素的个数称为线性表的长度:线性表内没有元素(长度为0)时,称为空表:表的起始位置称为表头,表的结束 ...

  2. Python学习笔记【第十四篇】:Python网络编程二黏包问题、socketserver、验证合法性

    TCP/IP网络通讯粘包问题 案例:模拟执行shell命令,服务器返回相应的类容.发送指令的客户端容错率暂无考虑,按照正确的指令发送即可. 服务端代码 # -*- coding: utf- -*- # ...

  3. [Postman]查找替换(5)

    在邮差中查找和替换 在Postman中快速轻松地查找和替换API项目中的文本.Postman应用程序使您能够执行全局查找和替换操作,该操作可在其各种组件(如集合,环境,全局和打开选项卡)中无缝工作.这 ...

  4. pickle模块及其API

    模块:pickle 所包含API列表: pickle.dumps : 把任意对象序列化成一个bytes pickle.dump : 直接把对象序列化后写入一个file-like Object pick ...

  5. Kubernetes集群搭建之Etcd集群配置篇

    介绍 etcd 是一个分布式一致性k-v存储系统,可用于服务注册发现与共享配置,具有以下优点. 简单 : 相比于晦涩难懂的paxos算法,etcd基于相对简单且易实现的raft算法实现一致性,并通过g ...

  6. VueJs(6)---V-on指令

    V-on指令 一.概述 v-on是用来绑定事件监听器,用在普通元素上时,只能监听原生 DOM 事件.用在自定义元素组件上时,也可以监听子组件触发的自定义事件. 在监听原生 DOM 事件时,方法以事件为 ...

  7. Django-用户模块与权限系统相关

    Django的用户模块与权限系统 Django的用户系统都提供哪些功能: 提供用户模块(User Model) 权限验证(默认添加已有模块的增加删除修改权限) 用户组与组权限功能 用户鉴权与登录功能 ...

  8. RabbitMQ管理界面

    Management Plugin rabbitmq-management插件提供基于HTTP的API方式管理和监控你的RabbitMQ服务器. 可以使用基于浏览器的UI界面,也可以使用命令行(rab ...

  9. 浅尝Spring Cloud Sleuth

    Spring Cloud Sleuth提供了分布式追踪(distributed tracing)的一个解决方案.其基本思路是在服务调用的请求和响应中加入ID,标明上下游请求的关系.利用这些信息,可以方 ...

  10. 转 Mac 使用ab性能测试工具

    Mac 使用ab命令进行压测 1.在Mac中配置Apache ①启动Apache,打开终端 sudo apachectl -v 如下显示Apache的版本 sudo apachectl start 这 ...