01Two operations: find and union
A disjoint set union (DSU, Union-Find) keeps elements split into groups that never overlap. It supports just two operations:
find(x): which group isxin? It returns a representative, sofind(a) == find(b)means "same group".union(a, b): merge the groups ofaandb.
You could relabel every member on each merge, but merging two big groups would then cost O(n). A graph search per question is even worse. DSU does both operations in almost O(1), with no way to split groups again (that is the price).
Typical uses: connected components while edges keep arriving, detecting a cycle when adding an edge, and Kruskal's minimum spanning tree, the next topic.