Minimum spanning tree algorithm with degree constraint 2