Floyd-Warshall algorithm: get the shortest paths
问题 Assume a graph is represented by a n x n dimension adjacency matrix. I know the how to get the shortest path matrix for all pairs. But I wonder is there a way to trace all the shortest paths? Blow is the python code implementation. v = len(graph) for k in range(0,v): for i in range(0,v): for j in range(0,v): if graph[i,j] > graph[i,k] + graph[k,j]: graph[i,j] = graph[i,k] + graph[k,j] 回答1: You have to add to your if statement a new matrix to store path reconstruction data (array p which is