Fix the Kruskal's algorithm in generating MST.

Current implementation uses only a "visited" mark to indicate whether an
edge is needed to be added into MST. This can sometimes generate
incorrect result.

To fix the problem a structure of disjoint-set is added. The structure
is used to decide if two nodes are already connected when adding an
edge.