public TopologicalSortShortestPath(WeightedDiGraph G, int s) { this.s = s; int V = G.V(); marked = new bool[V]; edgeTo = new Edge[V]; cost = new double[V]; for (var i = 0; i < V; ++i) { cost[i] = Double.MaxValue; } cost[s] = 0; DepthFirstPostOrder dfo = new DepthFirstPostOrder(G.ToDiGraph()); foreach (var v in dfo.PostOrder()) { foreach (var e in G.adj(v)) { Relax(G, e); } } }
public StronglyConnectedComponents(DiGraph G) { count = 0; var V = G.V(); marked = new bool[V]; id = new int[V]; var ts = new DepthFirstPostOrder(G.reverse()); foreach (var v in ts.PostOrder()) { if (!marked[v]) { dfs(G, v); count++; } } }