public KruskalMST(EdgeWeightedGraph G)
	{
		PriorityQueue<WeightedEdge> pq = new PriorityQueue<WeightedEdge>();
		for (WeightedEdge e : G.edges())
			pq.add(e);

		UnionFind uf = new UnionFindWQU(G.V());
		mst = new LinkedList<WeightedEdge>();

		while (!pq.isEmpty())
		{
			WeightedEdge e = pq.remove();
			int v = e.either(), w = e.other(v);

			// 2 find operations
			if (uf.connected(v, w))
				continue; // Adding v->w would result in a cycle as v and w are
							// already connected

			// 1 union operation
			uf.union(v, w);

			mst.add(e);
			weight += e.weight();
		}
	}