并查集(不相交集)的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输出集合的个数和总和 思路:并查集,关键在 ...
随机推荐
- [NOIP 2002普及组]产生数(floyd+高精度)
https://www.luogu.org/problem/P1037 题目描述 给出一个整数 n(n<1030) 和 k 个变换规则(k<=15). 规则: 一位数可变换成另一个一位数: ...
- 吴裕雄--天生自然python学习笔记:python 用pygame模块动画一让图片动起来
动画是游戏开发中不可或缺的要素,游戏中的角色只有动起来才会拥有“生命”, 但动画处理也是最让游戏开发者头痛的部分.Pygame 包通过不断重新绘制绘图窗口,短短几行代码就可以让图片动起来! 动画处理程 ...
- rest framework-restful介绍-长期维护
############### django框架-rest framework ############### # django rest framework 框架 # 为什么学习这个res ...
- conditon 实现等待/通知
synchronized 与wait() 和notify() notifyAll() 方法相结合可以实现等待 通知 ReetrantLock也可以实现同样的功能 需要借助condition对象,一个l ...
- maven-assembly-plugin 打包包含多余依赖问题一则
有同事反馈自己maven-assembly-plugin打的包里面多了很多mvn dependency:tree中没有的jar. 我当时只是试着把他的maven-assembly-plugin更新到了 ...
- F5 BIG-IP LTM会话保持
- mpvue框架的小程序和H5同时开发
demo链接1.样式统一为了达到共用一套样式,采用px2rem-loader和px2rpx-loader进行代码的打包,细节如下: 由于UI设计图是在蓝湖上标注,宽度750,选择像素 PX 样式中直接 ...
- hadoop创建两大错误:Bad connection to FS. command aborted. exception和Shutting down NameNode at hadoop
1.问题目录表: Error代码 failed on connection exception: java.net.ConnectException: Connection refused 3. ...
- windows下的tfjs-node安装异常总结
大约有半年没有写博客了,奔波于上海这座魔都之中.险些忘了自己是个有梦想的全栈工程师 书接上回,由于个人非常厌恶python的语法,半年前发现了tensorflow.js这个宝贝(下简称tfjs),喜出 ...
- SpringMVC学习笔记八:文件上传及多个文件上传
SpringMVC实现文件上传需要加入jar包,commons-fileupload-1.3.1.jar,commons-io-2.2.jar 项目目录树: pom.xml加入需要的包 <pro ...