Graph Theory37 sections · 1633 units
Open in Course

Recognizing DSU

Dynamic connectivity pattern

The signal is "after each road." You need to answer queries as edges arrive.

DSU tracks components dynamically. When you union two nodes, you merge their components and can update counts in O(α(n))O(\alpha(n)) time.

If you had all roads at once, you could use DFS. But here, roads arrive one by one, so DSU is the right tool. Use union by size to track component sizes directly. Maintain a running maximum size and a component counter that decrements on each successful union.