Loading...
Given n nodes (0 to n-1) and undirected edges, return the number of connected components.
Input: first line = n, second = edges as u:v comma-separated (or 'none').
5 0:1,1:2,3:4
2
5 represents the number of nodes (n=5) in the graph.0:1,1:2,3:4 are used to create an adjacency list, showing that nodes 0, 1, and 2 are connected, as well as nodes 3 and 4.