Fix a bug in Dijkstra code
This commit is contained in:
parent
f5be6f5d0b
commit
fc28ca6733
|
@ -581,9 +581,9 @@ while (!q.empty()) {
|
||||||
if (z[a]) continue;
|
if (z[a]) continue;
|
||||||
z[a] = 1;
|
z[a] = 1;
|
||||||
for (auto b : v[a]) {
|
for (auto b : v[a]) {
|
||||||
if (e[a]+b.second < e[b]) {
|
if (e[a]+b.second < e[b.first]) {
|
||||||
e[b] = e[a]+b.second;
|
e[b.first] = e[a]+b.second;
|
||||||
q.push({-e[b],b});
|
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
|
a good choice even if it is only needed to find a
|
||||||
single shortest path in the graph.
|
single shortest path in the graph.
|
||||||
However, the algorithm can only be used when the graph
|
However, the algorithm can only be used when the graph
|
||||||
is so small that a cubic time complexity is fast enough.
|
is so small that a cubic time complexity is fast enough.
|
||||||
|
|
Loading…
Reference in New Issue