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