Calculating the MST