unite(x, y): // 合併 2 個根節點
    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)