From fc28ca67333290f96c58b96bcca7b7c0cdc6faa0 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Tue, 7 Mar 2017 00:57:32 +0200 Subject: [PATCH] Fix a bug in Dijkstra code --- chapter13.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chapter13.tex b/chapter13.tex index f6461be..9d2f478 100644 --- a/chapter13.tex +++ b/chapter13.tex @@ -581,9 +581,9 @@ while (!q.empty()) { if (z[a]) continue; z[a] = 1; for (auto b : v[a]) { - if (e[a]+b.second < e[b]) { - e[b] = e[a]+b.second; - q.push({-e[b],b}); + if (e[a]+b.second < e[b.first]) { + e[b.first] = e[a]+b.second; + q.push({-e[b.first],b.first}); } } } @@ -797,4 +797,4 @@ algorithm is simple, the algorithm can be a good choice even if it is only needed to find a single shortest path in the graph. However, the algorithm can only be used when the graph -is so small that a cubic time complexity is fast enough. \ No newline at end of file +is so small that a cubic time complexity is fast enough.