minimum spanning tree, union find algorithm