# ノードxから経路圧縮
compress(x):
    if parent[x] ≠ x: # x が根ではない
        parent[x] ← compress(parent[x])

    return parent[x]

# 圧縮のシミュレーション
compress(5)