private IEnumerable <int> order;//顶点的拓扑排序 public Topological(IDirectedGraph g) { DirectedCycle directedCycle = new DirectedCycle(g); if (!directedCycle.HasCycle()) { //DAG DepthFirstOrder dfs = new DepthFirstOrder(g); order = dfs.ReversePost(); } }
private int count;//强连通分量的数量 /// <summary> /// 构造函数 /// </summary> /// <param name="g">有向图</param> public KosarajuSCC(IDirectedGraph g) { marked = new bool[g.V]; id = new int[g.V]; DepthFirstOrder order = new DepthFirstOrder(g.Reverse()); foreach (var w in order.ReversePost()) //获取逆图的拓扑排序 { if (!marked[w]) //在逆图的拓扑序上 { dfs(g, w); // ++count; } } }
private IEnumerable <int> order;//顶点的拓扑排序 public Topological(IDirectedGraph g) { DirectedCycle directedCycle = new DirectedCycle(g); if (!directedCycle.HasCycle()) { //DAG DepthFirstOrder dfs = new DepthFirstOrder(g); order = dfs.ReversePost(); } else { // throw new ArgumentException("不是 DAG!"); } }