Replies: 12 comments 12 replies
-
可以添加压位O(n)的线性序列并查集,类似rmq里面那个 |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
NOI2011 食物链那道题目可以用常数稍微大一点但是不带边权的并查集解决,方法: 每一个动物开 3 个点,代表这个动物染的三种颜色。 那么,每一次修改时,就会波及到三条边。 判断是否会出现冲突和合并即可。(不需要使用可持久化数据结构) |
Beta Was this translation helpful? Give feedback.
-
用了启发式合并,一些特殊例子(1->2 ; 2->3 ; n-1->n ; 1->n),dfs本来用O(n)的栈,变得应该不用O(n)了,猜测是O(nlogn)。还有人用bfs写,以此避免dfs的栈问题 |
Beta Was this translation helpful? Give feedback.
-
并查集删除的实现是不是存在一些问题?没有考虑是否是叶子结点?老师,这里有点不明白。 |
Beta Was this translation helpful? Give feedback.
-
可否在这页就显式地介绍一下秩和按秩合并的概念?感谢。 |
Beta Was this translation helpful? Give feedback.
-
删除某个节点时将父节点设为自身 self.pa[x] = x 在第一次删除后对此节点进行一定操作,这时是否就不能保证它是叶子节点? |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
启发式合并情况下,是不是也要把 find 改为: def find(self, x):
if self.pa[x] != x:
self.sizes[self.pa[x]] -= self.sizes[x]
self.pa[x] = self.find(self.pa[x])
return self.pa[x] |
Beta Was this translation helpful? Give feedback.
-
https://oi-wiki.org/ds/dsu/
Beta Was this translation helpful? Give feedback.
All reactions