summaryrefslogtreecommitdiff
path: root/graph/dijkstra.cpp
diff options
context:
space:
mode:
authorMZuenni <michi.zuendorf@gmail.com>2023-03-01 11:36:26 +0100
committerMZuenni <michi.zuendorf@gmail.com>2023-03-01 11:36:26 +0100
commit12afe719ce268bb10aa93a910079a44eb08999b8 (patch)
tree0937a117287eebe3942e0506d27143eff4980d09 /graph/dijkstra.cpp
parentad8456f7c5d44d3c647b3a368050a5d2f39ae3c3 (diff)
removed trailing whitespaces and use more structured bindings
Diffstat (limited to 'graph/dijkstra.cpp')
-rw-r--r--graph/dijkstra.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/graph/dijkstra.cpp b/graph/dijkstra.cpp
index 0b821dd..50c9654 100644
--- a/graph/dijkstra.cpp
+++ b/graph/dijkstra.cpp
@@ -7,15 +7,15 @@ void dijkstra(const vector<vector<path>> &adjlist, int start) {
dist[start] = 0; pq.emplace(0, start);
while (!pq.empty()) {
- path front = pq.top(); pq.pop();
- if (front.first > dist[front.second]) continue; // WICHTIG!
+ auto [dc, c] = pq.top(); pq.pop();
+ if (dc > dist[c]) continue; // WICHTIG!
- for (path e : adjlist[front.second]) {
- ll newDist = front.first + e.first;
- if (newDist < dist[e.second]) {
- dist[e.second] = newDist;
- prev[e.second] = front.second;
- pq.emplace(newDist, e.second);
+ for (auto [dx, x] : adjlist[c]) {
+ ll newDist = dc + dx;
+ if (newDist < dist[x]) {
+ dist[x] = newDist;
+ prev[x] = c;
+ pq.emplace(newDist, x);
}}}
//return dist, prev;
}