Carrying out normal Kruskal Algorithm
for ( let u = 1 ; u <= n ; u ++ ) { for ( let v = 0 ; v < g [ u ] . length ; v ++ ) { let x = find ( u ) ; let y = find ( g [ u ] [ v ] ) ; if ( x == y ) continue ; union ( x , y ) ; document . write ( u + " " + g [ u ] [ v ] + " " ) ; } } }