Function that returns number of nodes in the connected component having vertex u
| 18 | |
| 19 | // Function that returns number of nodes in the connected component having vertex u |
| 20 | ll DFS(ll u, bool* visited,vector<ll>* graph){ |
| 21 | visited[u]=true; |
| 22 | // initialize number of nodes to 1 |
| 23 | ll cc = 1; |
| 24 | for(auto i: graph[u]) |
| 25 | if(!visited[i]) |
| 26 | // recursively add the number of nodes in the component for each directly connected node |
| 27 | cc += DFS(i,visited, graph); |
| 28 | return cc; |
| 29 | } |
| 30 | int main(){ |
| 31 | fastio // for faster input/output |
| 32 |