Utility method for a depth first search among vertices
void dfs ( vector < int > g [ ] , int u , vector < bool > & visit ) { visit [ u ] = true ; for ( int i = 0 ; i < g [ u ] . size ( ) ; ++ i ) if ( ! visit [ g [ u ] [ i ] ] ) dfs ( g , g [ u ] [ i ] , visit ) ; }