I have seen people say that Floyd-Warshall can be modified (easily) to detect cycles. Note: I'm assuming the graph does not have negative cycles. I want to know how to modify the algorithm? And why is it correct? Also, what cycles can you make it detect? Shortest,Longest, of length k? -- and what adjustments in the algorithm do you need to make?
I read this question, that got me started thinking about this question: Find cycle of shortest length in a directed graph with positive weights
For the above link, I don't see why making the diagonal of adj. matrix = INFINITY gives us the cycles of shortest length going through (i,i).
Lastly, this site: http://en.algoritmy.net/article/45708/Floyd-Warshall-algorithm says:
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).
So I don't think I understand this because this seems wrong because if memory serves me correct, detecting all cycles can't be done in poly time. Am I misunderstanding what is being said? (Also, not really sure what is meant by matrix of predecessors.)