示例#1
0
        private int count;     // number of strongly-connected components

        /// <summary>Computes the strong components of the digraph <c>G</c>.</summary>
        /// <param name="G">the digraph</param>
        ///
        public KosarajuSharirSCC(Digraph G)
        {
            // compute reverse postorder of reverse graph
            DepthFirstOrder dfs = new DepthFirstOrder(G.Reverse());

            // run DFS on G, using reverse postorder to guide calculation
            marked = new bool[G.V];
            id     = new int[G.V];
            foreach (int v in dfs.ReversePost())
            {
                if (!marked[v])
                {
                    this.dfs(G, v);
                    count++;
                }
            }
            // check that id[] gives strong components
            Debug.Assert(check(G));
        }