Esempio n. 1
0
 public int solve() {
   UnionFind uf = new UnionFind(N);
   int minCost = 0;
   int total = 0;
   while (total < N) {
     Edge edge = edgeList.poll();
     if (uf.isSameSet(edge.from, edge.to)) continue;
     uf.unionSet(edge.from, edge.to);
     total = uf.sizeOfSet(edge.from);
     minCost += edge.weight;
   }
   return totalCost - minCost;
 }