Initialize a visiting matrix
let vis = new Array ( M + 1 ) ; for ( var i = 0 ; i < vis . length ; i ++ ) { vis [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < M + 1 ; i ++ ) { for ( let j = 0 ; j < N + 1 ; j ++ ) { vis [ i ] [ j ] = false ; } }