HDU6187-Destroy Walls
来源:互联网 发布:广联达套定额软件 编辑:程序博客网 时间:2024/05/29 10:54
Destroy Walls
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 272 Accepted Submission(s): 117
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 aren 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.
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
There are
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 integersxi,yi .
Then m lines follow, the ith line contains 3 integersui,vi,wi
|xi|,|yi|≤105
3≤n≤100000,1≤m≤200000
1≤ui,vi≤n,ui≠vi,0≤wi≤10000
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
Then m lines follow, the ith line contains 3 integers
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 11 11 -11 2 12 3 23 4 14 1 2
Sample Output
1 1
Source
2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
Recommend
liuyiding
题意:有一个n个结点m条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费
解题思路:生成一棵最大生成树即可
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cctype>#include <map>#include <cmath>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;const int maxn = 1e5 + 10;int n, m, x, y,f[100009];struct node{int u, v;LL w;bool operator<(const node &a)const{return w > a.w;}}a[200009];int Find(int x){return f[x] == x ? x : f[x] = Find(f[x]);}int main(){while (~scanf("%d%d", &n, &m)){LL ans = 0;for (int i = 1; i <= n; i++) scanf("%d%d", &x, &y);for (int i = 1; i <= m; i++) scanf("%d%d%lld", &a[i].u, &a[i].v, &a[i].w),ans+=a[i].w;sort(a + 1, a + 1 + m);for (int i = 1; i <= n; i++) f[i] = i;int cnt = 0;for (int i = 1; i <= m; i++){int uu = Find(a[i].u), vv = Find(a[i].v);if (uu == vv) { cnt++; continue; }f[uu] = vv;ans -= a[i].w;}printf("%d %lld\n", cnt, ans);}return 0;}
阅读全文
0 0
- HDU6187-Destroy Walls
- Destroy Walls
- HDU-6187:Destroy Walls
- hdu 6187 Destroy Walls
- HDU 6187 Destroy Walls(最大生成树)
- HDU 6187 Destroy Walls(对偶图最小生成树)
- 【HDU 6187 】Destroy Walls 【平面图+最大生成树】
- Destroy
- poj1161 - Walls
- AbstractApplicationContext -> destroy()
- WebView.destroy()
- angularjs-$destroy
- pku 1161 Walls
- poj 1161 Walls
- POJ 1161 Walls
- POJ 1161 walls
- SpringAnnotations By Craig Walls
- POJ-1161-Walls
- luoguP1091 合唱队形 题解
- CSDN-markdown
- Python05_面向对象
- svn cleanup: sqlite: database disk image is malformed
- Android Studio开启Lambda
- HDU6187-Destroy Walls
- 解决 Spring MVC No converter found for return value of type
- rabbitmq 安装-单点
- Android设置透明、半透明等效果
- synchronized同步语句块
- Canvas 贪吃蛇
- 零售模式4.0来临,零售行业BI重塑价值
- 树,二叉树,森林各种遍历总结:
- mybatis二级缓存不推荐使用