private void dfs(DiGraph G, int v) { marked[v] = true; foreach (int w in G.Adj(v)) if (!marked[w]) dfs(G, w); }
private void dfs(DiGraph G, int v) { onStack[v] = true; marked[v] = true; foreach (int w in G.Adj(v)) { if (this.hasCycle()) { return; } else if (!marked[w]) { edgeTo[w] = v; dfs(G, w); } else if (onStack[w]) { cycle = new Stack <int>(); for (int x = v; x != w; x = edgeTo[x]) { cycle.Push(x); } cycle.Push(w); cycle.Push(v); } } onStack[v] = false; }
private void dfs(DiGraph G, int v) { pre.Enqueue(v); marked[v] = true; foreach (int w in G.Adj(v)) if (!marked[w]) dfs(G, w); post.Enqueue(v); reversePost.Push(v); }
private void dfs(DiGraph G, int v) { marked[v] = true; foreach (int w in G.Adj(v)) { if (!marked[w]) { dfs(G, w); } } }
private void dfs(DiGraph G, int v) { pre.Enqueue(v); marked[v] = true; foreach (int w in G.Adj(v)) { if (!marked[w]) { dfs(G, w); } } post.Enqueue(v); reversePost.Push(v); }
private void dfs(DiGraph G, int v) { onStack[v] = true; marked[v] = true; foreach (int w in G.Adj(v)) if (this.hasCycle()) return; else if (!marked[w]) { edgeTo[w] = v; dfs(G, w); } else if (onStack[w]) { cycle = new Stack<int>(); for (int x = v; x != w; x = edgeTo[x]) cycle.Push(x); cycle.Push(w); cycle.Push(v); } onStack[v] = false; }