Ejemplo n.º 1
0
 private void visit(EdgeWeightedGraph G, int v) {
   // Mark v and add to pq all edges from v to unmarked vertices.
   marked[v] = true;
   for (Edge e : G.adj(v)) {
     if (!marked[e.other(v)]) {
       pq.insert(e);
     }
   }
 }
Ejemplo n.º 2
0
 public void visit(int v) {
   marked[v] = true;
   for (Edge e : G.adj(v)) {
     int w = e.other(v);
     if (marked[w]) continue;
     if (disTo[w] > e.weight()) {
       disTo[w] = e.weight();
       if (!pq.contains(w)) {
         pq.insert(w, e.weight());
       } else pq.changeKey(w, e.weight());
       edgeTo[w] = v;
     }
   }
 }
Ejemplo n.º 3
0
 private void visit(EdgeWeightedGraph G, int v) // Add v to tree; update data structures.
     {
   marked[v] = true;
   for (Edge e : G.adj(v)) {
     int w = e.other(v);
     if (marked[w]) continue; // v-w is ineligible.
     if (e.weight() < distTo[w]) // Edge e is new best connection from tree to w.
     {
       edgeTo[w] = e;
       distTo[w] = e.weight();
       if (pq.contains(w)) pq.change(w, distTo[w]);
       else pq.insert(w, distTo[w]);
     }
   }
 }
Ejemplo n.º 4
0
 private void visit(EdgeWeightedGraph G, int v) {
   marked[v] = true;
   for (Edge e : G.adj(v)) {
     if (!marked[e.other(v)]) pq.offer(e);
   }
 }