Answer the question
In order to leave comments, you need to log in
How to find the shortest path between two vertices in a graph?
Task: find the shortest path between two vertices of a weighted undirected graph and output it as a sequence of vertices. The graph is given by the adjacency matrix.
I use the Floyd-Warshall algorithm for finding the shortest paths between all pairs of vertices
( e-maxx.ru/algo/floyd_warshall_algorithm).
for (int k=0; k<n; ++k)
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
d[i][j] = min (d[i][j], d[i][k] + d[k][j]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question