Example #1
0
        //
        public KosarajuSCC(Digraph G)
        {
            marked = new bool[G.GetVertices()];
            id     = new int[G.GetVertices()];
            DigraphTopological d = new DigraphTopological(G.Reverse());

            foreach (int s in d.ReversePost) // reversePost Order here
            {
                if (!marked[s])
                {
                    Dfs(G, s);
                    count++;
                }
            }
        }
Example #2
0
        /**
         * Determines whether the digraph {@code G} has a topological order and, if so,
         * finds such a topological order.
         * @param G the digraph
         */
        public DigraphTopological2(Digraph G)
        {
            V = G.GetVertices();
            DirectedCycle finder = new DirectedCycle(G);

            if (!finder.IsCycle())
            {
                DigraphTopological d = new DigraphTopological(G);
                Order = d.ReversePost;
                rank  = new int[G.GetVertices()];
                int i = 0;
                foreach (int v in Order)
                {
                    rank[v] = i++;
                }
            }
        }