Source: https://ranger.uta.edu/~alex/courses/3318/lectures/18_mst_a2.pdf