Visited array for dfs
let vis = Array . from ( { length : n } , ( _ , i ) => 0 ) ; for ( let k = 0 ; k < n ; k ++ ) { vis [ k ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) { if ( vis [ i ] == 0 ) { answer = Math . max ( answer , dfs ( i , adj , vis ) ) ; } } return answer ; }