I can't figure out how to find the number of connected components from an undirected disconnected graph.
the input I'm getting is like this:
the top number is the number of vertices and the rest of the numbers are the edges, eg. 1--2 is an edge.
Is there a way that you can implement DFS algorithm to find the number of connected components? like increment a variable every time DFS is called or something?
Thanks in advance