예제 #1
0
        private static void Main(string[] args)
        {
            int employeesCount = int.Parse(Console.ReadLine());
            bool[,] graph = new bool[employeesCount, employeesCount];
            bool[] visited = new bool[employeesCount];

            for (int i = 0; i < employeesCount; i++)
            {
                string inputLine = Console.ReadLine();
                for (int j = 0; j < employeesCount; j++)
                {
                    if (inputLine[j] == 'N')
                    {
                        graph[i, j] = false;
                    }
                    else
                    {
                        graph[i, j] = true;
                    }
                }
            }

            var graphClass = new Graph(graph);
            graphClass.Traverse();
            graphClass.ShowSort();
        }
예제 #2
0
        static void Main()
        {
            int employeesCount = int.Parse(Console.ReadLine());

            List<Node>[] edges = new List<Node>[employeesCount];

            int[,] matrix = new int[employeesCount, employeesCount];
            char[,] c = new char[employeesCount, employeesCount];
            int[] sums = new int[employeesCount];

            for (int i = 0; i < c.GetLength(0); i++)
            {
                string line = Console.ReadLine();
                edges[i] = new List<Node>();

                for (int j = 0; j < c.GetLength(1); j++)
                {
                    c[i, j] = line[j];
                    if (line[j] == 'Y')
                    {
                        edges[i].Add(new Node(j, 0));
                    }
                }

                if(edges[i].Count == 0)
                {
                    sums[i] = 1;
                }
            }

            for (int i = 0; i < matrix.GetLength(1); i++)
            {
                for (int j = 0; j < matrix.GetLength(0); j++)
                {
                    if(c[j, i] == 'Y')
                    {
                        matrix[j, i] = 1;
                    }
                }
            }

            var graph = new Graph(matrix);
            graph.TestDfs();
            var elements = graph.SortedElements;

            for (int i = 0; i < elements.Count; i++)
            {
                var current = edges[elements[i]];
                foreach (var item in current)
                {
                    sums[elements[i]] += sums[item.Vertex];
                }
            }

            Console.WriteLine(sums.Sum());
        }