【发布时间】:2013-12-06 20:20:13
【问题描述】:
我看到有人说 Floyd-Warshall 可以(轻松地)修改以检测周期。注意:我假设图表没有负循环。我想知道如何修改算法?为什么它是正确的?另外,你可以让它检测到哪些周期?最短,最长,长度为 k? -- 您需要对算法进行哪些调整?
我读了这个问题,这让我开始思考这个问题: Find cycle of shortest length in a directed graph with positive weights
对于上面的链接,我不明白为什么要制作 adj 的对角线。 matrix = INFINITY 为我们提供了通过 (i,i) 的最短长度的循环。
最后,这个网站:http://en.algoritmy.net/article/45708/Floyd-Warshall-algorithm 说:
Floyd-Warshall algorithm can be easily modified to detect cycles.
If we fill negative infinity value at the diagonal of the matrix and run the
algorithm, then the matrix of predecessors will contain also all cycles in the graph
(the diagonal will not contain only zeros, if there is a cycle in the graph).
所以我不认为我理解这一点,因为这似乎是错误的,因为如果我的记忆正确,检测所有周期就不能在多时间内完成。我是否误解了所说的内容? (另外,不太清楚前辈矩阵是什么意思。)
【问题讨论】:
标签: graph-theory cycle floyd-warshall