Working version of Kruskal's algorithm. The running time is very bad though.