diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2023-03-28 13:25:59 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2023-03-28 13:25:59 +0200 |
| commit | fe5fa1141efeb7454c763dbd2645fb4ff04487a3 (patch) | |
| tree | f2197bb94ce80ab2fae886177dfa9b0bd11538ac /graph/havelHakimi.cpp | |
| parent | 3b91d2662310aee532cc84e1447824459671767e (diff) | |
merged
Diffstat (limited to 'graph/havelHakimi.cpp')
| -rw-r--r-- | graph/havelHakimi.cpp | 12 |
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; } |
