Initializing every node as a tree with single node .
for ( let i = 0 ; i < n ; i ++ ) { id [ i ] = i ; sz [ i ] = 1 ; } let e = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 2 , 4 ] , [ 2 , 5 ] , [ 4 , 6 ] , [ 6 , 7 ] ] ; let q = e . length ; UnionUtil ( e , W , q ) ;