Пример #1
0
        /// <summary>
        /// topological sort in an edge-weighted digraph
        /// </summary>
        /// <param name="g"></param>
        public Topological(EdgeWeightedDigraph g)
        {
            EdgeWeightedDirectedCycle finder = new EdgeWeightedDirectedCycle(g);

            if (!finder.HasCycle())
            {
                DepthFirstOrder dfs = new DepthFirstOrder(g);
                order = dfs.ReversePost();
            }
        }
Пример #2
0
        public KosarajuSharirSCC(Digraph g)
        {
            //compute reverse postorder of reverse graph
            DepthFirstOrder dfo = 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 dfo.ReversePost())
            {
                if (!marked[v])
                {
                    dfs(g, v);
                    count++;
                }
            }
        }