The private dfs(G, v) method traverses ALL the vertices that are connected to v by some path.
The count() method returns the number of such vertices; i.e., it returns the number of vertices in the connected component containing v.