Пример #1
0
        /// <summary>
        /// 用edges[]中的边来构造一幅加权有向图来检测环——基本思路:
        /// 在图中dfs,判断到目前节点已被marked并且在栈中,就是一个环
        /// </summary>
        private void findNegativeCycle()
        {
            int V = edges.Length;
            DirectedWeightedEdgeGraph G = new DirectedWeightedEdgeGraph(V);
            foreach (var e in edges)//用edges来构造一幅加权有向图
                if (e != null)
                    G.AddEdge(e);

            DirectedWeightedCycle dc = new DirectedWeightedCycle(G);
            cycle = dc.GetCycle();//疑问:貌似找到的不一定是负权重环????
        }
Пример #2
0
        /// <summary>
        /// 用edges[]中的边来构造一幅加权有向图来检测环——基本思路:
        /// 在图中dfs,判断到目前节点已被marked并且在栈中,就是一个环
        /// </summary>
        private void findNegativeCycle()
        {
            int V = edges.Length;
            DirectedWeightedEdgeGraph G = new DirectedWeightedEdgeGraph(V);

            foreach (var e in edges)//用edges来构造一幅加权有向图
            {
                if (e != null)
                {
                    G.AddEdge(e);
                }
            }

            DirectedWeightedCycle dc = new DirectedWeightedCycle(G);

            cycle = dc.GetCycle();//疑问:貌似找到的不一定是负权重环????
        }