Minimum spanning tree algorithm, implemented with data structure