← Quit0 / 0 correct
RustHard1 of 256

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
}