Driver code
let n = 10 ; let g = new Array ( n + 1 ) ; for ( let i = 0 ; i < g . length ; i ++ ) g [ i ] = [ ] ; g [ 1 ] . push ( 2 ) ; g [ 2 ] . push ( 1 ) ; g [ 1 ] . push ( 3 ) ; g [ 3 ] . push ( 1 ) ; g [ 1 ] . push ( 4 ) ; g [ 4 ] . push ( 1 ) ; g [ 2 ] . push ( 5 ) ; g [ 5 ] . push ( 2 ) ; g [ 2 ] . push ( 6 ) ; g [ 6 ] . push ( 2 ) ; g [ 3 ] . push ( 7 ) ; g [ 7 ] . push ( 3 ) ; g [ 4 ] . push ( 10 ) ; g [ 10 ] . push ( 4 ) ; g [ 8 ] . push ( 7 ) ; g [ 7 ] . push ( 8 ) ; g [ 9 ] . push ( 7 ) ; g [ 7 ] . push ( 9 ) ; let v = [ ] ; v . push ( 7 ) ; v . push ( 3 ) ; v . push ( 8 ) ; document . write ( findLCA ( n , g , v ) + " " ) ;