Practicing Kruskal algorithm.
Time complexity is O(|E|log|V|)