我正在尝试计算图表中的负权重周期数(加权或未加权)。但我没有找到如何计算这个。 例如:if Directed加权图
nodes:[1,2,3,4,5]
edges:[(1,2,w=1),(1,4,w=4),(2,3,w=2),(3,1,w=2),(3,5,w=1),(4,5,w=2),(5,4,w=7),(4,3,w=-6),(5,1,w=-7)]
cycles weight
[1, 4, 5, 1] -1
[1, 4, 3, 5, 1] -8
[1, 4, 3, 1] 0
[1, 2, 3, 5, 1] -3
[1, 2, 3, 1] 5
[3, 5, 4, 3] 2
[4, 5, 4] 9
注意:
Negative Cycles: A negative cycle is a cycle in a weighted graph whose total weight is negative.
因此,在此图中有三个负循环([1,4,5,1],[1,4,3,5,1],[1,2,3,5,1])。 任何人都可以建议我如何实现负循环次数。