Union-Find Template: Derive find / union / count
Subtitle / Summary Union-Find is not a pair of function names to memorize first. It solves one concrete problem: decide whether two nodes already belong to the same set, and merge two sets when a connection appears. Reading time: 10-12 min Tags: Hot100, Union-Find, DSU, graph, connectivity SEO keywords: Union-Find, DSU, Disjoint Set Union, find, union, count, path compression Meta description: A Python Union-Find template guide that derives parent, find, union, count, connected, path compression, and connected component counting. A - Algorithm: Start From Set-Merging Pressure Tiny task: merge sets and answer connectivity Suppose we have 5 nodes: ...