Count the connected groups
There are n nodes numbered 0 to n - 1 and a list of undirected edges, each [a, b]. Two nodes are in the same group if a chain of edges joins them. Return the number of groups.
Edges may repeat, may join a node to itself and may close cycles; n may be 0.
Besides the tests, one large input (9,000 nodes) with a ~300 ms limit (scaled to your device's speed): brute force won't pass.
Examples
count_components(5, [[0,1],[1,2],[3,4]])→2count_components(5, [[0,1],[1,2],[2,3],[3,4]])→1count_components(4, [])→4