Comments

i think that you can keep a curr_cost variable while building the spanning tree initially the curr_cost is zero then during building the MST you need to choose edges in such a way that (curr_cost | edge weight == curr_cost) else take the minimum edge weight and oring it with the curr_cost