I want to reconstruct the path from source to destination vertex in this graph problem.
How can I store the path, and how can I retrieve it after I have found the minimal cost from s to d?
Please help开发者_如何学运维 me to find a simple answer?
For example at the point,
adjmat[i][j] = Math.min(adjMat[i][j],adjMat[i][k]+adjMat[k][j]);
I need to add a path and I need to retrieve it.
The Wikipedia article about the Floyd-Warshall algorithm provides an explanation and pseudocode for your problem.
Use optimal matrix with Floyd-Warshall Algorithm to reconstruct path. It construct path simulatneously. Refer to Introduction to graph theory- by Narsingh Deo for actual algorithm
精彩评论