This is the pseudo-code for the Floyd-Warshall algorithm for shortest paths detection:
I was wondering if it would be possible to add a check that will test if there are no cycles with negative weights?
I think it is possible, but I do not know how to check.
CodePudding user response:
Take the sum of all negative weights in the graph.
You have a negative cycle if and only if you find a path to a weight that is below that minimum.