题干:

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–√)(0.6∗2,0.6∗3).

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

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,yixi,yi.

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

|xi|,|yi|≤105|xi|,|yi|≤105

3≤n≤100000,1≤m≤2000003≤n≤100000,1≤m≤200000

1≤ui,vi≤n,ui≠vi,0≤wi≤100001≤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

题目大意:

  有一个V座塔(告诉你每座塔的x,y坐标)M条边(链接两个塔)的带边权无向平面图,有一个人在一个区域,坐标是,要拆一些墙使得他可以到达任意一个区域,问最小花费。

解题报告:

不难想到,其实可以将每一个联通区域看成一个点,将一堵墙看做两个点之间的边被切断了,边权就是对应的wi,也就是说你需要让他们连通起来,即让他变成一个连通图,这样我们只需要构造一棵MST就好了。但是对于如何把整个图划分成点,这就比较麻烦,我们可以换个角度分析,其实就是直接考虑删边。其实删边的过程就是破环的过程,也就是让最后的图中没有一个环,所以我们考虑做法,对每一个块,求个最大生成树就好了。那么怎么统计块数呢?其实也不用这么麻烦,直接建一个虚点,对每个点都连边就好了,然后直接求最大生成树,最后用总边权减去最大生成树的权值,剩下的一定就是都要删去的边。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 5e5 + 5;
int x[MAX],y[MAX];
struct Node {int u,v;ll w;
} e[MAX];
int tot,n,m;
bool cmp(Node a,Node b) {return a.w > b.w;
}
int f[MAX];
int getf(int v) {return f[v] == v ? v : f[v] = getf(f[v]);
}
int merge(int u,int v) {int t1 = getf(u);int t2 = getf(v);f[t2] = t1;
}
int main()
{int u,v;ll w;while(~scanf("%d%d",&n,&m)) {tot=0;for(int i = 1; i<=n+1; i++) f[i] = i;for(int i = 1; i<=n; i++) scanf("%d%d",x+i,y+i);ll ans2 = 0;for(int i = 1; i<=m; i++) {scanf("%d%d%lld",&u,&v,&w);e[i].u = u,e[i].v = v;e[i].w = w;ans2 += w;}tot=m;for(int i = 1; i<=n; i++) {e[++tot].u = i;e[tot].v = n+1;e[tot].w = -123123;}sort(e+1,e+m+1,cmp);ll ans = 0,ee=0;for(int i = 1; i<=tot; i++) {int u = e[i].u;int v = e[i].v;if(getf(u) == getf(v)) continue;if(e[i].w >= 0) {ans += e[i].w;ee++;}     merge(u,v);}printf("%lld %lld\n",m-ee,ans2-ans);}return 0 ;
}

【HDU - 6187】Destroy Walls(思维,最大生成树)相关推荐

  1. HDU 6187 Destroy Walls

    Destroy Walls Long times ago, there are beautiful historic walls in the city. These walls divide the ...

  2. I - Destroy Walls (HDU - 6187)

    - 题目大意 有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费. - 解题思路 先开始想不通,看了别人突然恍然大悟,根据欧拉公式我们可以知道 ...

  3. Destroy Walls

    点击打开链接 Problem Description Long times ago, there are beautiful historic walls in the city. These wal ...

  4. CodeForces - 1408E Avoid Rainbow Cycles(思维+最大生成树)

    题目链接:点击查看 题目大意:给出 m 个集合,每个集合中都有数个点,每个点的取值范围为 [ 1 , n ] ,对于每个集合而言,其中的点互相连边,边的颜色为其集合的编号,每次操作可以删除点,删除掉第 ...

  5. Save your cats Aizu - 2224(思维+最大生成树)

    传送门 题意: 给出一个图,这个图形封闭区域(可能多个可能一个也没有),问最少需要破坏多少边使得封闭区域不封闭.先给出每个点的坐标,然后给出每条边的关系. 题解: 这个题因为封闭区域可能一个可能多个可 ...

  6. hdu 4263(有限制的生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4263 思路:将红边和蓝边单独求一次生成树,求的红边最多可以加入的边数cntr,蓝边最多可以加入的边数c ...

  7. HDU - 6486 Flower(思维)

    HDU - 6486 Flower 题目大意:有n堆草每次只能对n-1堆操作每次只能减1问最少操作几次能把这些草剪到相同高度如果不能输出-1 我们让n-1个数减1实际上可以看成使得剩下的那一个数加1. ...

  8. HDU - 5637 Transform (思维、bfs预处理)

    HDU - 5637 题目大意: 给出n个数的序列a,对于一个整数x,有两种操作: 1.改变x二进制中任一位 2.将x变为x^a[i] m次查询,每次查询输入两个整数x和y,问x最少经过多少次操作可以 ...

  9. HDU - 6438(贪心+思维)

    链接:HDU - 6438 题意:给出 n ,表示 n 天.给出 n 个数,a[i] 表示第 i 天,物品的价格是多少.每天可以选择买一个物品,或者卖一个已有物品,也可以什么都不做,问最后最大能赚多少 ...

最新文章

  1. JTable动态显示隐藏列
  2. 用Jmeter实现SQLServer数据库的增删查改
  3. 【C++】44.使用xx.so动态链接库
  4. iphone11计算机出现问题,苹果11出现死机现象
  5. Elastic-Job中的DataFlowJob
  6. android多屏应用程序,微软也尝试“多屏协同” Windows系统可以运行安卓程序
  7. HDU2855 Fibonacci Check-up 矩阵的应用
  8. access汇总_区块链或密码学相关论文汇总,持续更新中
  9. jconsole是否可以在生产环境使用_jconsole使用
  10. MySQL数据库基础(外键约束、添加索引)
  11. 在 Linux 下搭建 Git 服务器
  12. paip. java的 函数式编程 大法
  13. nginx+php配置
  14. php 回显,PHP实时回显 实时输出结果的方法 实时反馈结果到浏览器
  15. oracle取字段第三位字符,oracle字符串根据分隔符号获取第几个元素
  16. python-乌龟吃小鱼(小游戏)
  17. 5个免费商用音频素材网站
  18. McAfee设置信任文件
  19. USB大容量存储设备无法启动该怎么办?
  20. SSM框架超市进销存出库入库仓库管理系统(idea开发javaweb-javaee-j2ee-springboot) 退货管理 销售管理 供应商管理 客户管理 员工管理 以及库存统计和盘存统计

热门文章

  1. [剑指offer]面试题第[59-1]题[Leetcode][第239题][JAVA][滑动窗口的最大值][单调队列][优先队列]
  2. [剑指offer]面试题第[66]题[构建乘积数组][Leetcode][JAVA][第238题][除自身以外数组的乘积][数组]
  3. gdal 压缩tif_Python | GDAL处理影像
  4. 南京二本有什么计算机学校,南京有什么好的二本学校?
  5. java multimap 序列化_C++ JSON库的使用
  6. html a 点击防止刷新,a标签点击跳转页面不刷新的问题
  7. C/C++中near和far的区别
  8. android studio adb 命令行,Android Studio如何配置adb以及经常使用命令
  9. wpf 使子ui元素可视区域不超过父元素_对游戏UI设计的一点思考
  10. python alter table_python(pymysql)之mysql简单操作