题干:

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. 为啥程序员下班后只关显示器从不关电脑?看看各大网站的答案~
  2. hi!亲爱的好友,欢迎您的光临
  3. 密码设置Android设备管理
  4. VTK:Disk用法实战
  5. 数字范围按位与Python解法
  6. 怎样查看Oracle的数据库SID和用户名
  7. C#开源资源大汇总(2)
  8. 如何避免DevOps变革的六大“焦油坑”
  9. 【Kafka】kafka Java api 获取 kafka topic 或者 partition 占用的磁盘大小
  10. 【leetcode】Merge Sorted Array
  11. mysql-8.0.14图文安装_mysql8.0.14安装配置方法图文教程(通用)
  12. AngularJS Directive 命名规则
  13. Python-Cartopy制图学习02-中国2010年5月干旱情况空间制图
  14. aspnetpager使用介绍
  15. 使用strace查看后台程序stdout输出
  16. 公交查询系统Android源代码,公交查询源码
  17. html页面整体变灰,整个页面html变灰
  18. python学习之初窥门径
  19. 终止被占用的端口,localhost:8000
  20. 美团面试常见问题总结

热门文章

  1. 我的收藏 - 音频处理相关网站
  2. 可以无限增加iPhone 的图标吗?
  3. [剑指offer]面试题第[59-1]题[Leetcode][第239题][JAVA][滑动窗口的最大值][单调队列][优先队列]
  4. Android studio实现底部导航,AndroidStudio制作底部导航栏以及用Fragment实现切换功能...
  5. python变量生命周期_python 变量定义及变量生命周期
  6. C#命名空间namespace中不能直接包含字段(变量)或方法(函数)之类的成员
  7. tkinter如何lable重复显示到同一行中_如何创建包含 CAD 导入和选择的仿真 App
  8. html5新增的js,HTML5新增属性data-*和js/jquery之间的交互及注意事项
  9. 解决 avformat_alloc_context无法识别的问题
  10. sip消息概念(一)