并查集(不相交集)的Remove操作
给并查集(不相交集)的添加一个\(Remove(X)\)操作,该操作把\(X\)从当前的集合中除去并把它放到自己的集合中。
实现思想
英文原句
We assume that the tree is implemented with pointers instead of a simple array. Thus Find will return a pointer instead of an actual set name. We will keep an array to map set numbers to their tree nodes. Union and Find are implemented in the standard manner. To perform \(Remove(X)\), first perform a \(Find(X)\) with path compression. Then mark the node containing \(X\) as vacant. Create a new one-node tree with \(X\) and have it pointed to by the appropriate array entry. The time to perform a Remove is the same as the time to perform a Find, except that there potentially could be a large number of vacant nodes. To take care of this, after \(N\) Removes are performed, perform a Find on every node, with path compression. If a \(Find(X)\) returns a vacant root, then place \(X\) in the root node, and make the old node containing \(X\) vacant. The results of guarantee that this will take linear time, which can be charged to the \(N\) Removes. At this point, all vacant nodes (indeed all nonroot nodes) are children of a root, and vacant nodes can be disposed (if an array of pointers to them has been kept). This also guarantees that there are never more than \(2N\) nodes in the forest and preserves the \(Mα(M, N)\) asymptotic time bound.
百度翻译
我们假设树是用指针实现的,而不是简单的数组。因此\(Find\)将返回一个指针,而不是实际的集合名。我们将保留一个数组来将集合编号映射到它们的树节点。\(Union\)和\(Find\)以标准方式实现。要执行\(Remove(X)\),首先使用路径压缩执行\(Find(X)\)。然后将包含\(X\)的节点标记为空。用\(X\)创建一个新的单节点树,并用适当的数组项指向它。执行移除的时间与执行查找的时间相同,只是可能存在大量空闲节点。为了解决这个问题,在执行\(N\)个remove之后,在每个节点上执行一个\(Find\),并进行路径压缩。如果\(Find(X)\)返回一个空根,那么将\(X\)放在根节点中,并使包含\(X\)的旧节点成为空节点。结果保证这将花费线性时间,这将被计入\(N\)个移除。此时,所有空节点(实际上所有非根节点)都是根的子节点,可以释放空节点(如果保留了指向它们的指针数组)。这也保证了森林中不超过\(2N\)个节点,并保持了\(Mα(M,N)\)渐近时间界。
并查集(不相交集)的Remove操作的更多相关文章
- HDU 2473 Junk-Mail Filter 并查集,虚拟删除操作
http://acm.hdu.edu.cn/showproblem.php?pid=2473 给定两种操作 第一种是合并X Y 第二种是把X分离出来,就是从原来的集合中分离出来,其它的关系不变. 关键 ...
- uva 6910 - Cutting Tree 并查集的删边操作,逆序
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- hdu4496并查集的删边操作
题意: 给你一个图,问你删除一些边后还有几个连通快.. 思路: 典型的并查集删边操作,并查集的删边就是先把不删除的边并查集一边(本题没有不删除的边),然后逆序吧所有要删除的边以 ...
- UVa 11987 Almost Union-Find(支持删除操作的并查集)
传送门 Description I hope you know the beautiful Union-Find structure. In this problem, you’re to imple ...
- HDU 2473 - Junk-Mail Filter ,并查集的删点
Problem Description Recognizing junk mails is a tough task. The method used here consists of two ste ...
- HDU——2473Junk-Mail Filter(并查集删点)
Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 并查集(删除) UVA 11987 Almost Union-Find
题目传送门 题意:训练指南P246 分析:主要是第二种操作难办,并查集如何支持删除操作?很巧妙的方法:将并查集树上p的影响消除,即在祖先上(sz--, sum -= p),然后为p换上马甲:id[p] ...
- 并查集——HDOJ-1232-畅通工程
并查集 并查集(Union-Find Sets)是一种非常精巧而实用的数据结构,它主要用于处理一些不相交集合的合并问题,在合并之前,需要先判断两个元素是否属于同一集合,这就需要用查找操作来实现.一些常 ...
- A Bug's Life(hdu1829种类并查集)
题意:有一群虫子,现在给你一些关系,判断这些关心有没有错 思路:向量种类并查集,下面讲一下向量的种类并查集 本题的各个集合的关心有两种0同性,1异性,怎么判断有错, 1.先判断他们是否在一个集合,即父 ...
- UVA 11987 - Almost Union-Find(并查集)
UVA 11987 - Almost Union-Find 题目链接 题意:给定一些集合,操作1是合并集合,操作2是把集合中一个元素移动到还有一个集合,操作3输出集合的个数和总和 思路:并查集,关键在 ...
随机推荐
- vue axios从服务器加载图片并显示
使用场景: 后台传给前端一个图片二进制流,但是要添加httpp header,但是在传统的用img标签查看图片,无法添加http header this.$axios({ method: 'get', ...
- Linux svn 服务器配置--转
转自 http://my.oschina.net/lionel45/blog/298305 留存备份. Linux搭建SVN 服务器 作者: 沈小然 日期:2014年 8月 5日 1 ...
- poj 1463树形dp 树的最小覆盖
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...
- day43-线程概念
#1.进程:程序不能单独运行,要将程序加载到内存当中,系统为它分配资源才能运行,而这种执行的程序就是进程. #程序和进程的区别在于:程序是指令的集合,它是进程运行的静态描述文本:进程是程序的一次执行活 ...
- Linux 杀死进程方法大全(kill,killall)
杀死进程最安全的方法是单纯使用kill命令,不加修饰符,不带标志. 首先使用ps -ef命令确定要杀死进程的PID,然后输入以下命令: # kill -pid 注释:标准的kill命令通常 ...
- gpio 的配置
1.时钟使能 B引脚RCC时钟脉冲启动.|(或)表示只要第三个为1就行. 也可以写为RCC_APB2ENR | = 0X0008; 2.配置GPIO的输出模式以及速度 3 . 如果是 0号引脚:GP ...
- LootCode-链表排序-Java
链表排序 0.来源 来源:力扣(LeetCode) 题目链接:https://leetcode-cn.com/problems/sort-list 1.题目描述 在 O(n log n) 时间复杂度和 ...
- 项目部署篇之二——linux下安装jdk1.8
1.下载jdk1.8 百度云下载后,直接通过xftp拖到你想放的目录下就行了,实在方便 链接:https://pan.baidu.com/s/1hQl0_3owT776lRO9mHSbXA 提取码:2 ...
- linux 下安装及查看java的安装路径
一.Linux下安装JDK 1.下载文件 从官网下载合适版本如:jdk-8u191-linux-x64.tar.gz 2.安装文件 1.在 /usr/ 目录下创建 java文件夹mkdir /usr/ ...
- 第一次作业:使用java实现word count
github项目地址: https://github.com/changrui520/homework 作业要求: 可执行程序命名为:wc.exe. 该程序处理用户需求的模式为:wc.exe [par ...