Creating Adjacency list
function constructTree ( n , edges ) { let adjl = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { adjl . push ( [ ] ) ; } for ( let e = 0 ; e < edges . length ; e ++ ) { let u = edges [ e ] [ 0 ] ; let v = edges [ e ] [ 1 ] ; adjl [ u ] . push ( v ) ; adjl [ v ] . push ( u ) ; } return adjl ; }