HDU 6187 Destroy Walls(对偶图最小生成树)
来源:互联网 发布:js 将 替换成换行符 编辑:程序博客网 时间:2024/05/15 11:29
Destroy Walls
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 236 Accepted Submission(s): 96
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
2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
Recommend
liuyiding
题目大意:
有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一个区域,问最小花费。
解题思路:
首先可以发现题目就是要求一个平面图对偶图的最小生成树。
根据欧拉公式我们可以知道对于一个有k个连通分量的平面图的区域数
AC代码:
#include <stdio.h>#include <vector>#include <iostream>#include <string.h>#include <algorithm>using namespace std;#define LL long longconst int MAXV=100000+3;const int MAXE=200000+3;struct Edge{ int from, to, cost; Edge(int f=0, int t=0, int c=0):from(f), to(t), cost(c){} bool operator < (const Edge &other)const { return cost>other.cost; }}edge[MAXE];int V, E;int par[MAXV], high[MAXV];int findfather(int x){ return par[x]=par[x]==x?x:findfather(par[x]);}bool unite(int a, int b){ int fa=findfather(a), fb=findfather(b); if(fa==fb) return false; if(high[fa]>high[fb]) par[fa]=fb; else { par[fb]=fa; if(high[fa]==high[fb]) ++high[fb]; } return true;}void init()//初始化{ for(int i=0;i<=V;++i) { par[i]=i; high[i]=0; }}int main(){ while(~scanf("%d%d", &V, &E)) { init(); for(int i=0;i<V;++i) { int x, y; scanf("%d%d", &x, &y); } LL ans=0; for(int i=0;i<E;++i) { scanf("%d%d%d", &edge[i].from, &edge[i].to, &edge[i].cost); ans+=edge[i].cost; } sort(edge, edge+E); int cnt=0;//保留的边数 for(int i=0;i<E;++i) if(unite(edge[i].from, edge[i].to)) { ans-=edge[i].cost; ++cnt; } printf("%d %lld\n", E-cnt, ans); } return 0;}
- HDU 6187 Destroy Walls(对偶图最小生成树)
- HDU 6187 Destroy Walls(最大生成树)
- 【HDU 6187 】Destroy Walls 【平面图+最大生成树】
- HDU-6187:Destroy Walls
- hdu 6187 Destroy Walls
- Destroy Walls
- HDU 3035 War(对偶图求最小割)
- HDU6187-Destroy Walls
- hdu 3870 Catch the Theves(对偶图,最短路,最小割)
- HDU 3870 Catch the Theves(对偶图的最小割转最短路)
- [HDU](1233)还是通畅工程 ---最小生成树(图)
- HDU 1102(最小生成树)
- HDU 3371(最小生成树,Prim)
- hdu 1102 (最小生成树)
- hdu 1863(最小生成树)
- hdu 2122 (prime 最小生成树)
- hdu 3371 最小生成树(有重边)
- hdu 1102(最小生成树)
- vue项目部署到apache服务器页面空白的问题
- 公司的一道考试题算法分析——大数据量整数排序
- redis事务实现原理(源码分析)【转】
- EL表达式
- Spring注解
- HDU 6187 Destroy Walls(对偶图最小生成树)
- iOS开发 UIView分类
- Qt开发:DOM解析xml实现读、写、增、删、改
- 工作流学习笔记——Activiti流程定义管理三步曲
- 学生信息管理系统
- 希尔排序算法(java版)
- 一些常见的Linux命令
- 珍爱生命,远离抱怨和抱怨之人。抱怨能让你陷入更惨的境地!
- Android ListView功能扩展,实现高性能的瀑布流布局