visited array for dfs
int vis [ n ] ; for ( int k = 0 ; k < n ; k ++ ) { vis [ k ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( ! vis [ i ] ) { answer = max ( answer , dfs ( i , adj , vis ) ) ; } } return answer ; }