← Quit0 / 0 correct
How is union-find (disjoint set) typically implemented in Rust?
fn find(p: &mut Vec<usize>, mut x: usize) -> usize {
while p[x] != x {
p[x] = p[p[x]]; // path halving
x = p[x];
}
x
}How is union-find (disjoint set) typically implemented in Rust?
fn find(p: &mut Vec<usize>, mut x: usize) -> usize {
while p[x] != x {
p[x] = p[p[x]]; // path halving
x = p[x];
}
x
}