路徑壓縮 | 會動的演算法

符號表示

資料

路徑壓縮
搜尋從起點到根節點的路徑。compress(x)
更新父節點。parent[x] ← compress(parent[x])
要壓縮的路徑

演算法動畫

路徑壓縮
路徑壓縮 | 路徑壓縮