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

题干:

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 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440463.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【HDU - 6184】Counting Stars(三元环计数,二分,优化暴力,O(m*sqrt(m)),图论)

题干&#xff1a; Little A is an astronomy lover, and he has found that the sky was so beautiful! So he is counting stars now! There are n stars in the sky, and little A has connected them by m non-directional edges. It is guranteed that no edges connec…

php 取oracle图片,在PHP中将图片存放ORACLE中_php

我这里提供一个用php操纵blob字段的例子给你&#xff0c;希望能有所帮助&#xff01;这个例子是把用户上传的图片文件存放到BLOB中。假设有一个表&#xff0c;结构如下&#xff1a;CREATE TABLE PICTURES (ID NUMBER,http://www.gaodaima.com/44856.html在PHP中将图片存放oracl…

【HDU - 6183】Color it(CDQ分治 或 动态开点线段树)

题干&#xff1a; Do you like painting? Little D doesnt like painting, especially messy color paintings. Now Little B is painting. To prevent him from drawing messy painting, Little D asks you to write a program to maintain following operations. The speci…

php create()方法,ThinkPHP中create()方法自动验证实例

ThinkPHP中create()方法自动验证实例2020-06-16 04:24:32自动验证是ThinkPHP模型层提供的一种数据验证方法&#xff0c;可以在使用create创建数据对象的时候自动进行数据验证。原理&#xff1a;create()方法收集表单($_POST)信息并返回&#xff0c;同时触发表单自动验证&#x…

【蓝桥杯官网试题 - 历届试题】格子刷油漆(dp)

题干&#xff1a; 问题描述 X国的一段古城墙的顶端可以看成 2*N个格子组成的矩形&#xff08;如下图所示&#xff09;&#xff0c;现需要把这些格子刷上保护漆。   你可以从任意一个格子刷起&#xff0c;刷完一格&#xff0c;可以移动到和它相邻的格子&#xff08;对角相邻也…

oracle软件静默安装程序,【oracle】静默安装 oracle 11gr2

【序言】oracle 提供了静默安装方法在不适用图形界面的情况下安装 oracle 软件 ,创建db,配置netca,快速完成oracle 的部署。在以下情形中可以使用静默安装a OUI 的 GUI 界面远程交互比较慢 .b 数据库服务器无法使用图形界面访问.c 批量部署oracle (标准环境统一情况下可以使用o…

【2050 Programming Competition - 2050 一万人码 】非官方部分题解(HDU)

1001 开场白 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12147 Accepted Submission(s): 3502 Problem Description 来自世界各地的年青人在 https://2050.org.cn 握手团聚&#xff0c; 他们是航空…

oracle数据库建表视频,Oracle数据库的创建表全

CREATE TABLE "库名"."表名" ("FEE_ID" VARCHAR2(10 BYTE) constraint ABS_FEE_ID primary key,--主键&#xff0c;必须要有序列"BANK_GROUP_ID" VARCHAR2(5 BYTE),"ABS_PRODUCT_ID" VARCHAR2(30 BYTE))TABLESPACE "表…

oracle dump enq hw,经典故障分析 - ASSM引发的索引争用与 enq HW -contentio

作者介绍&#xff1a;孙加鹏 云和恩墨技术顾问六年Oracle技术顾问经验&#xff0c;所服务的行业包括电信运营商、金融业、制造业等。擅长Oracle的故障诊断、高可用架构、升级迁移等。目前主要服务于上海金融类客户。1故障概述2017年07月24日11:58左右&#xff0c;客户核心数据库…

【ZOJ - 3946】Highway Project(最短路子图,维护双权值,贪心,最小树形图)

题干&#xff1a; Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project. The Marjar Empire has N cities (including…

【ZOJ - 3956】Course Selection System(01背包)

题干&#xff1a; There are n courses in the course selection system of Marjar University. The i-th course is described by two values: happiness Hi and credit Ci. If a student selects m courses x1, x2, ..., xm, then his comfort level of the semester can be…

Linux把文件移动到容器外,Docker容器与主机之间拷贝文件的方法

一般情况下&#xff0c;我们在启动Docker容器的时候可以使用-v参数映射宿主机的文件或者目录到容器里&#xff0c;这样的话&#xff0c;在宿主机相关目录下的文件修改会自动在容器里生效。但是&#xff0c;如果我们已经启动了一个容器的话&#xff0c;就只能使用下面的这种方式…

【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp)

题干&#xff1a; David has a white board with 2 \times N2N grids.He decides to paint some grids black with his brush.He always starts at the top left corner and ends at the bottom right corner, where grids should be black ultimately. Each time he can mov…

【HDU - 6514】Monitor(二维差分,前缀和)

题干&#xff1a; Monitor Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others) Total Submission(s): 872 Accepted Submission(s): 145 Problem Description Xiaoteng has a large area of land for growing crops, and the land…

【CodeForces - 1153D】Serval and Rooted Tree(树形dp)

题干&#xff1a; Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before. As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree. …

实验楼Linux基础挑战2答案,实验楼-Linux基础-实验二 Linux的基本概念及操作

一、实验介绍1.1 实验内容实验楼环境介绍常用 Shell 命令及快捷键Linux 使用小技巧1.2 实验知识点Linux 基本命令通配符的使用查看帮助文档二、桌面环境1.Linux 桌面环境介绍相对于现在的 Windows 系统&#xff0c;UNIX/Linux 本身是没有图形界面的&#xff0c;我们通常在 UNIX…

【HDU - 1533】Going Home(网络流,二分图最优匹配,KM算法)

题干&#xff1a; On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step h…

【ZOJ - 4029】Now Loading!!!(整除分块,思维,二分,前缀和)

题干&#xff1a; 其中 zi 是第i次询问后的z。 解题报告&#xff1a; 因为有取log运算&#xff0c;所以分母的取值肯定不会超过30种&#xff0c;所以分每一个分母的时候&#xff0c;用前缀和优化一个和&#xff0c;最后求乘积就行了。&#xff08;其实不需要快速幂&#xff0c…

【ZOJ - 4032】Magic Points (思维,几何,构造)

题干&#xff1a; 解题报告&#xff1a; 想到了&#xff0c;这样绕圈构造。但是这样有个问题&#xff0c;最后一个点如何构造。 刚开始想的是n奇数 &#xff0c; 就8 10 这样的连一条&#xff0c;n偶数 就8 11 这样的连一条&#xff0c;随便构造一下就行&#xff0c;但是发…

android 仿真翻页动画,Android 两Activity之间动画效果(1)---------翻页效果

用Android rotate动画实现翻页效果&#xff0c;效果如图&#xff1a;要实现上面动画&#xff0c;首先搞明白rotate动画原理&#xff1b;(1)Degrees坐标&#xff1a;0度(360度)270度90度 顺时针旋转 180(2)rotate 关键属性fromDegrees 开始旋转时角度 toDegrees 结束时的角…