Kruskals algorithm