1void DFS(int start, vector<int> v[],vector<int> &visited, int &count)
2{
3 visited[start] = 1;
4 count++;
5 for(int i= 0; i<v[start].size(); ++i)
6 {
7 if(visited[v[start][i]] == 0)
8 DFS(v[start][i], v, visited);
9 }
10}
11---------------------------------------------------
12 for(int i=1;i<=n;++i)
13{
14 if(visited[i] == 0 )
15 {
16 connected++;
17 int count=0;
18 DFS(i,v,visited,count);
19 cout<<"This component has "<<count<<" nodes"<<"\n";
20 }
21}