Ejemplo n.º 1
0
 /**
  * Contracts the edges incidents on the vertices {@code s} and {@code t} of
  * the given edge-weighted graph.
  * 
  * @param G the edge-weighted graph
  * @param s the vertex {@code s}
  * @param t the vertex {@code t}
  * @return a new edge-weighted graph for which the edges incidents on the
  *         vertices {@code s} and {@code t} were contracted
  */
 private EdgeWeightedGraph contractEdge(EdgeWeightedGraph G, int s, int t) {
     EdgeWeightedGraph H = new EdgeWeightedGraph(G.V());
     for (int v = 0; v < G.V(); v++) {
         for (Edge e : G.adj(v)) {
             int w = e.other(v);
             if (v == s && w == t || v == t && w == s) continue;
             if (v < w) {
                 if (w == t)      H.addEdge(new Edge(v, s, e.weight()));
                 else if (v == t) H.addEdge(new Edge(w, s, e.weight()));
                 else             H.addEdge(new Edge(v, w, e.weight()));
             }
         }
     }
     return H;
 }