コード例 #1
0
        public static int ReachableFrom(DirectedGraph g)
        {
            for (int i = 0; i < g.g.Length; i++)
            {
                Algorithms.Dfs dfs = new Algorithms.Dfs(g, i);
                //if (dfs.GetResult())
                //{
                //    return i + 1;
                //}

                bool res = true;
                for (int j = 0; j < dfs.marked.Length; j++)
                {
                    if (dfs.marked[j] == false)
                    {
                        res = false;
                        break;
                    }
                }
                if (res)
                {
                    return(i + 1);
                }
            }
            return(-1);
        }
コード例 #2
0
        public static int ReachableFrom(DirectedGraph g)
        {
            for (int i = 0; i < g.g.Length; i++)
            {
                Algorithms.Dfs dfs = new Algorithms.Dfs(g, i);
                //if (dfs.GetResult())
                //{
                //    return i + 1;
                //}

                bool res = true;
                for (int j = 0; j < dfs.marked.Length; j++)
                {
                    if (dfs.marked[j] == false)
                    {
                        res = false;
                        break;
                    }
                }
                if (res)
                {
                    return i + 1;
                }
            }
            return -1;
        }