unite(x, y): // 合并两个根节点 if rank[x] > rank[y]: parent[y] ← x else: parent[x] ← y if rank[x] = rank[y]: rank[y]++ # 合并的模拟 unite(0, 1) unite(2, 3) unite(1, 3) unite(4, 5) unite(3, 5)