예제 #1
0
 /**
  * Determines a depth-first order for the edge-weighted digraph <tt>G</tt>.
  *
  * @param G the edge-weighted digraph
  */
 public DepthFirstOrder(MapGraph G) {
   pre = new int[G.V()];
   post = new int[G.V()];
   postorder = new Queue<Integer>();
   preorder = new Queue<Integer>();
   marked = new boolean[G.V()];
   for (int v = 0; v < G.V(); v++) if (!marked[v]) dfs(G, v);
 }
예제 #2
0
 private void dfs(MapGraph G, int v) {
   marked[v] = true;
   pre[v] = preCounter++;
   preorder.enqueue(v);
   for (MapEdge e : G.adj(v)) {
     int w = e.to();
     if (!marked[w]) {
       dfs(G, w);
     }
   }
   postorder.enqueue(v);
   post[v] = postCounter++;
 }