Exemple #1
0
        // topological sort
        // backwards Adj -> Bdj

        public static int[][] TransitiveClosure(Graph g)
        {
            int[][] closure = new int[g.V][];
            for (int v = 0; v < g.V; v++)
            {
                closure[v] = Bits.BitsArray(g.V);
            }
            for (int v = 0; v < g.V; v++)
            {
                Bits.MarkBit(closure[v], v);
                for (int i = 0; i < g.Deg(v); i++)
                {
                    int v1 = g.BdjV(v, i);
                    for (int u = 0; u < g.V; u++)
                    {
                        if (Bits.IsMarked(closure[v], u))
                        {
                            Bits.MarkBit(closure[v1], u);
                        }
                    }
                }
            }
        }