disjoint-set
for(int i = 1; i<=V; i++){
parent[i] = i;
}
function Find(x){
if x.parent == x
return x
else
return Find(x.parent)
}
function Union(x, y){
xRoot := Find(x)
yRoot := Find(y)
xRoot.parent := yRoot
}1. path compression
2. union by rank
summary
관련 문제
Last updated
Was this helpful?