Exemplo n.º 1
0
        public KosarajuSharirSCC(Diagraph g)
        {
            marked      = new bool[g.V];
            connectedId = new int[g.V];

            DepthFirstOrder depthFirstOrder = new DepthFirstOrder(g);

            foreach (int i in depthFirstOrder.reversePost())
            {
                if (!marked[i])
                {
                    dfs(g, i);
                    connectedComponentCounter++;
                }
            }
        }
        public Topological(Diagraph G)
        {
            DirectedCycle finder = new DirectedCycle(G);

            if (!finder.hasCycle())
            {
                DepthFirstOrder dfs = new DepthFirstOrder(G);
                order   = dfs.reversePost();
                rankArr = new int[G.V];
                int i = 0;
                foreach (int v in order)
                {
                    rankArr[v] = i++;
                }
            }
        }