Create a visited array for DFS and initialize it as false .
var visit = new Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) { visit [ i ] = [ ] ; for ( var j = 0 ; j < MAX ; j ++ ) { visit [ i ] . push ( false ) ; } }