Union-Find (Disjoint Set)

Track which nodes belong to the same group and merge groups quickly, used to detect cycles and build networks.