Given nodes labeled from to and a list of undirected edges, count the number of connected components in the graph.
Example: , edges returns (components {0,1,2} and {3,4}). You're solving the canonical Union-Find problem.
Union all edges, then count distinct roots. Constraints: from to , edges from to .