diff options
| author | Paul Jungeblut <paul.jungeblut@gmail.com> | 2016-10-06 19:44:29 +0200 |
|---|---|---|
| committer | Paul Jungeblut <paul.jungeblut@gmail.com> | 2016-10-06 19:44:29 +0200 |
| commit | 7cf8f4e10ac917ed8b900e43e294e26200329ee8 (patch) | |
| tree | e8d625e0277df3ec1c7aa12efa79262358a4eded /graph | |
| parent | fd6f3c1b886b8baf2fb02789717f021abe4a3fe0 (diff) | |
Saving space in Dijkstra.
Diffstat (limited to 'graph')
| -rw-r--r-- | graph/dijkstra.cpp | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/graph/dijkstra.cpp b/graph/dijkstra.cpp index 1fb5f53..52cb57e 100644 --- a/graph/dijkstra.cpp +++ b/graph/dijkstra.cpp @@ -2,22 +2,16 @@ void dijkstra(int start) { priority_queue<ii, vector<ii>, greater<ii> > pq; vector<int> dist(NUM_VERTICES, INF), parent(NUM_VERTICES, -1); - - dist[start] = 0; - pq.push(ii(0, start)); + dist[start] = 0; pq.push(ii(0, start)); while (!pq.empty()) { ii front = pq.top(); pq.pop(); int curNode = front.second, curDist = front.first; - - if (curDist > dist[curNode]) continue; + if (curDist > dist[curNode]) continue; // WICHTIG! for (auto n : adjlist[curNode]) { int nextNode = n.first, nextDist = curDist + n.second; if (nextDist < dist[nextNode]) { dist[nextNode] = nextDist; parent[nextNode] = curNode; pq.push(ii(nextDist, nextNode)); - } - } - } -} +}}}} |
