python 并查集模板
def find(x):
if x!=fa[x]:
fa[x] = find(fa[x])
return fa[x]
def join(x, y):
left = find(x)
right = find(y)
if left!=right:
if size[left]<size[right]:
fa[left] = right
size[right]+=size[left]
else:fa[right] = left
size[left]+=size[right]