Exemplo n.º 1
0
 // run Prim's algorithm
 private void prim(EdgeWeightedGraph G, int s) {
     scan(G, s);
     while (!pq.isEmpty()) {                        // better to stop when mst has V-1 edges
         Edge e = pq.delMin();                      // smallest edge on pq
         int v = e.either(), w = e.other(v);        // two endpoints
         assert marked[v] || marked[w];