summaryrefslogtreecommitdiff
path: root/graph/havelHakimi.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2023-03-28 13:25:59 +0200
committermzuenni <michi.zuendorf@gmail.com>2023-03-28 13:25:59 +0200
commitfe5fa1141efeb7454c763dbd2645fb4ff04487a3 (patch)
treef2197bb94ce80ab2fae886177dfa9b0bd11538ac /graph/havelHakimi.cpp
parent3b91d2662310aee532cc84e1447824459671767e (diff)
merged
Diffstat (limited to 'graph/havelHakimi.cpp')
-rw-r--r--graph/havelHakimi.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/graph/havelHakimi.cpp b/graph/havelHakimi.cpp
index 8d5d6ab..6246fe0 100644
--- a/graph/havelHakimi.cpp
+++ b/graph/havelHakimi.cpp
@@ -5,14 +5,12 @@ vector<vector<int>> havelHakimi(const vector<int>& deg) {
while (!pq.empty()) {
auto [degV, v] = pq.top(); pq.pop();
if (sz(pq) < degV) return {}; //impossible
- vector<pair<int, int>> todo;
- for (int i = 0; i < degV; i++) {
- auto [degU, v] = pq.top(); pq.pop();
+ vector<pair<int, int>> todo(degV);
+ for (auto& e : todo) e = pq.top(), pq.pop();
+ for (auto [degU, u] : todo) {
adj[v].push_back(u);
adj[u].push_back(v);
- if (degU > 1) todo.push_back({degU - 1, u});
- }
- for (auto e : todo) pq.push(e);
- }
+ if (degU > 1) pq.push({degU - 1, u});
+ }}
return adj;
}