Source: https://jeffe.cs.illinois.edu/teaching/algorithms/book/07-mst.pdf