Function to find MEX of each subtree of tree
function solve ( A , C ) { let n = A ; let tree = new Array ( n + 1 ) . fill ( 0 ) . map ( ( ) => [ ] ) ; for ( let i of edges ) { tree [ i [ 0 ] ] . push ( i [ 1 ] ) ; tree [ i [ 1 ] ] . push ( i [ 0 ] ) ; } let sol = new Array ( n ) . fill ( 0 ) ;