Minimum spanning tree algorithm implementation.