给并查集(不相交集)的添加一个\(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操作的更多相关文章

  1. HDU 2473 Junk-Mail Filter 并查集,虚拟删除操作

    http://acm.hdu.edu.cn/showproblem.php?pid=2473 给定两种操作 第一种是合并X Y 第二种是把X分离出来,就是从原来的集合中分离出来,其它的关系不变. 关键 ...

  2. uva 6910 - Cutting Tree 并查集的删边操作,逆序

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  3. hdu4496并查集的删边操作

    题意:       给你一个图,问你删除一些边后还有几个连通快.. 思路:       典型的并查集删边操作,并查集的删边就是先把不删除的边并查集一边(本题没有不删除的边),然后逆序吧所有要删除的边以 ...

  4. UVa 11987 Almost Union-Find(支持删除操作的并查集)

    传送门 Description I hope you know the beautiful Union-Find structure. In this problem, you’re to imple ...

  5. HDU 2473 - Junk-Mail Filter ,并查集的删点

    Problem Description Recognizing junk mails is a tough task. The method used here consists of two ste ...

  6. HDU——2473Junk-Mail Filter(并查集删点)

    Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  7. 并查集(删除) UVA 11987 Almost Union-Find

    题目传送门 题意:训练指南P246 分析:主要是第二种操作难办,并查集如何支持删除操作?很巧妙的方法:将并查集树上p的影响消除,即在祖先上(sz--, sum -= p),然后为p换上马甲:id[p] ...

  8. 并查集——HDOJ-1232-畅通工程

    并查集 并查集(Union-Find Sets)是一种非常精巧而实用的数据结构,它主要用于处理一些不相交集合的合并问题,在合并之前,需要先判断两个元素是否属于同一集合,这就需要用查找操作来实现.一些常 ...

  9. A Bug's Life(hdu1829种类并查集)

    题意:有一群虫子,现在给你一些关系,判断这些关心有没有错 思路:向量种类并查集,下面讲一下向量的种类并查集 本题的各个集合的关心有两种0同性,1异性,怎么判断有错, 1.先判断他们是否在一个集合,即父 ...

  10. UVA 11987 - Almost Union-Find(并查集)

    UVA 11987 - Almost Union-Find 题目链接 题意:给定一些集合,操作1是合并集合,操作2是把集合中一个元素移动到还有一个集合,操作3输出集合的个数和总和 思路:并查集,关键在 ...

随机推荐

  1. 正则表达式中 /s 可以帮助“.”匹配所有的字符,包括换行,从而实现【\d\D】的功能

    正则表达式中 /s 可以帮助“.”匹配所有的字符,包括换行,从而实现[\d\D]的功能

  2. mysql字段值为null时排序问题

    -- DESC 降序时候默认null值排在后面.ASC升序时默认null值排在前面,可使用 IS NULL处理 ORDER BY score desc,gmPrice IS NULL,gmPrice, ...

  3. SwaggerConfig

    package me.zhengjie.common.swagger2; import com.google.common.base.Predicates; import org.springfram ...

  4. P2448 无尽的生命(树状数组+离散化)

    题目描述 逝者如斯夫,不舍昼夜! 叶良辰认为,他的寿命是无限长的,而且每天都会进步. 叶良辰的生命的第一天,他有1点能力值.第二天,有2点.第n天,就有n点.也就是S[i]=i 但是调皮的小A使用时光 ...

  5. K - Wand(组合数+错排公式)

    N wizards are attending a meeting. Everyone has his own magic wand. N magic wands was put in a line, ...

  6. linux系统用户管理(一)

    Linux系统用户管理1.用户管理*****2.Linux用户命令****3.用户创建的原理***4.密码管理***5.组命令管理**6.身份切换*****7.sudo提升权限***** 我们现在所使 ...

  7. Android drawable 加载效果

    <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:ones ...

  8. WebService如何根据WSDL文件转换成本地的C#类

    WebService有两种使用方式,一种是直接通过添加服务引用,另一种则是通过WSDL生成. 添加服务引用大家基本都用过,这里就不讲解了. 那么,既然有直接引用的方式,为什么还要通过WSDL生成呢? ...

  9. mysqli存储过程

    <?php$link = mysqli_connect('localhost','root','','chinatupai');  $sql = "call getEmail('000 ...

  10. Jenkins 2 如何使用 PowerShell 以及自定 build fail (指定 exit code)

    Jenkins 除了用來做為 CI(持續性整合) 工具外,也可以與其他 plugin 配合達成其他目的(e.g.IIS restart.檔案壓縮備份-),今天就來看看可以怎麼與 PowerShell ...