public SCC1(Digraph1 g) { _ids = new int[g.V]; _marked = new bool[g.V]; Stack <int> vertices = DfsOrder(g); Digraph1 gt = g.Transpose(); Dfs(gt, vertices); }
private void DfsVisit(Digraph1 g, int u) { _ids[u] = _count; foreach (var v in g.Adj(u)) { if (!_marked[v]) { _marked[v] = true; DfsVisit(g, v); } } }
private void DfsOrderVisit(Digraph1 g, int u, Stack <int> stack) { foreach (var v in g.Adj(u)) { if (!_marked[v]) { _marked[v] = true; DfsOrderVisit(g, v, stack); } } stack.Push(u); }
private static Digraph1 GetDigraph1(int v, Tuple <int, int>[] edges) { Digraph1 g = new Digraph1(v); foreach (var edge in edges) { g.AddEdge(edge.Item1, edge.Item2); } Console.WriteLine("Direct Graph 1: "); Console.WriteLine(g.ToString()); return(g); }
public Digraph1 Transpose() { Digraph1 g = new Digraph1(V); for (int i = 0; i < V; i++) { ICollection <int> adj = Adj(i); foreach (var j in adj) { g.AddEdge(j, i); } } return(g); }
private Stack <int> DfsOrder(Digraph1 g) { Stack <int> stack = new Stack <int>(); for (int i = 0; i < g.V; i++) { if (!_marked[i]) { _marked[i] = true; DfsOrderVisit(g, i, stack); } } return(stack); }
private void Dfs(Digraph1 g, Stack <int> vertices) { for (int i = 0; i < g.V; i++) { _marked[i] = false; } foreach (int i in vertices) { if (!_marked[i]) { _marked[i] = true; DfsVisit(g, i); _count++; } } }