Check if u and v are in the same tree: plaintext function connected(u, v) return findRoot(u) = findRoot(v) Simple: find both roots, compare.
This replaces Union-Find for connectivity but with added power: - Supports edge deletion (cut) - Supports path queries - Supports rerooting Union-Find is faster ( vs ) but limited to connectivity. Time: amortized.