8000 Merge pull request #1 from PirateOfAndaman/PirateOfAndaman-patch-1 · cp-algorithms/cp-algorithms@5f342d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f342d3

Browse files
Merge pull request #1 from PirateOfAndaman/PirateOfAndaman-patch-1
Update dijkstra.md
2 parents 77ef08a + 08cc8a6 commit 5f342d3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/graph/dijkstra.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Note that if some vertices are unreachable from the starting vertex $s$, the val
3838

3939
### Restoring Shortest Paths
4040

41-
Usually one needs to know not only the lengths of shortest paths but also the shortest paths themselves. Let's see how to maintain sufficient information to restore the shortest path from $s$ to any vertex. We'll maintain an array of predecessors $p[]$ in which for each vertex $v \ne s$ $p[v]$ is the penultimate vertex in the shortest path from $s$ to $v$. Here we use the fact that if we take the shortest path to some vertex $v$ and remove $v$ from this path, we'll get a path ending in at vertex $p[v]$, and this path will be the shortest for the vertex $p[v]$. This array of predecessors can be used to restore the shortest path to any vertex: starting with $v$, repeatedly take the predecessor of the current vertex until we reach the starting vertex $s$ to get the required shortest path with vertices listed in reverse order. So, the shortest path $P$ to the vertex $v$ is equal to:
41+
Usually one needs to know not only the lengths of shortest paths but also the shortest paths themselves. Let's see how to maintain sufficient information to restore the shortest path from $s$ to any vertex. We'll maintain an array of predecessors $p[]$ in which for each vertex $v \ne s$, $p[v]$ is the penultimate vertex in the shortest path from $s$ to $v$. Here we use the fact that if we take the shortest path to some vertex $v$ and remove $v$ from this path, we'll get a path ending in at vertex $p[v]$, and this path will be the shortest for the vertex $p[v]$. This array of predecessors can be used to restore the shortest path to any vertex: starting with $v$, repeatedly take the predecessor of the current vertex until we reach the starting vertex $s$ to get the required shortest path with vertices listed in reverse order. So, the shortest path $P$ to the vertex $v$ is equal to:
4242

4343
$$P = (s, \ldots, p[p[p[v]]], p[p[v]], p[v], v)$$
4444

0 commit comments

Comments
 (0)
0