Пример #1
0
        public IList <int> EventualSafeNodes(int[][] adjacencyMatrix)
        {
            // all nodes in a strongly connected component is unsafe
            // because they can get in a loop
            _graph = GraphUtilities.GetDiGraphFromAdjacencyMatrix(adjacencyMatrix);
            // for each node, we try to see if it can reach a cycle
            // a cycle is reached when during a DFS, a back edge is discovered
            foreach (var node in _graph.Nodes)
            {
                if (node.Color == Color.Uncolored)
                {
                    Visit(node);
                }
            }
            var safeList = new List <int>();

            foreach (var node in _graph.Nodes)
            {
                if (node.Color != Color.Black)
                {
                    safeList.Add(node.Label);
                }
            }
            safeList.Sort();
            return(safeList);
        }