Cheers, I am trying to solve the problem of minimum length cycle in a directed graph, and I came across a solution that suggested that I should tweak the Floyd-Warshall algorithm to solve that. It stated that instead of setting path[i][i] = 0
I should instead set path[i][i] = INFINITY
, but I don't exactly understand why that is the case! I find that the main diagonal of the array used by Floyd-Warshall does not change, so how can it help me to see the path of the cycle? I understand that the generated array of the algorithm helps me find the shortest path of a pair. e.g. path[i][j]
gives me the shortest path from i to j but, although the intuition stays the same, I see that nothing changes, and I can't take the desired result.
I even tried visualizing the process, using this website here, I generated a graph which contained many cycles inside it, but although the diagonal is initialized with infinity, it does not get changed. Can anyone explain what am I missing or what I can do to solve my problem?