并查集(不相交集)的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输出集合的个数和总和 思路:并查集,关键在 ...
随机推荐
- spring boot GlobalExceptionHandler @RestControllerAdvice @ExceptionHandler
package me.zhengjie.common.exception.handler; import lombok.extern.slf4j.Slf4j; import me.zhengjie.c ...
- B. Split a Number(字符串加法)
Dima worked all day and wrote down on a long paper strip his favorite number nn consisting of ll dig ...
- 绿洲作业第一周 - Y3每日中文学习任务清单
尽量每天完成一首古诗. 如果孩子另有学习安排,可在周日(2.16)23:59前,完成任务.有兴趣.学有余力的孩子可以自我拓展其中的“寒假读诗”.
- Docker系列六: 使用Docker官方公共仓库和私有仓库
使用公共仓库 登陆官方网站:https://hub.docker.com/ 注册账号和密码 在Docker hub中创建一个资源, create respositories, 创建后会提示 ...
- Java源码之ArrayList
本文源码均来自Java 8 总体介绍 Collection接口是集合类的根接口,Java中没有提供这个接口的直接的实现类.Set和List两个类继承于它.Set中不能包含重复的元素,也没有顺序来存放. ...
- DataGrip设置时区
新版本DataGrip以默认时区取世界标准时间.要想时间显示正常,需要将时区变为上海时区,可手动在连接配置里设置参数.如下图: 操作步骤1.右键打开你想要修改的数据库连接的Properties菜单:2 ...
- [LC] 149. Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- VisualStudio使用HALCIN_NET控件
遵循以下步骤在一个应用中添加Halcon/.Net: 一. 定义工具箱 Halcon/.net 不仅提供了一个类库,而且提供了一个控件:HWindowControl,它包含一个显示图像处理结果的Hal ...
- 利用git上传文件到github
git add 文件名称/. "."代表全部 git commit -m -a git push -u origin master 推送到远程仓库 ---------------- ...
- Springmvc+Mybatis+shiro整合
Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码学和会话管理.使用Shiro的易于理解的API,您可以快速.轻松地获得任何应用程序,从最小的移动应用程序到最大的网络 ...