A graph has n nodes numbered 0 to n - 1 and some undirected edges. Return the number of connected components: groups of nodes that can reach each other.
For n = 5 and edges = [[0, 1], [1, 2], [3, 4]] the answer is 2.
Example 1
Input:
count_components(5, [[0, 1], [1, 2], [3, 4]])
Output:
2
Example 2
Input:
count_components(3, [])
Output:
3
0 <= n <= 1000000 <= len(edges) <= 2000000 <= a, b < n; there may be repeated edges.No results yet
Run your code to check it against the examples, or submit to run every test.