diff options
| author | MZuenni <michi.zuendorf@gmail.com> | 2023-03-01 11:36:26 +0100 |
|---|---|---|
| committer | MZuenni <michi.zuendorf@gmail.com> | 2023-03-01 11:36:26 +0100 |
| commit | 12afe719ce268bb10aa93a910079a44eb08999b8 (patch) | |
| tree | 0937a117287eebe3942e0506d27143eff4980d09 /graph/havelHakimi.cpp | |
| parent | ad8456f7c5d44d3c647b3a368050a5d2f39ae3c3 (diff) | |
removed trailing whitespaces and use more structured bindings
Diffstat (limited to 'graph/havelHakimi.cpp')
| -rw-r--r-- | graph/havelHakimi.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/graph/havelHakimi.cpp b/graph/havelHakimi.cpp index 135c4b0..8d5d6ab 100644 --- a/graph/havelHakimi.cpp +++ b/graph/havelHakimi.cpp @@ -3,17 +3,16 @@ vector<vector<int>> havelHakimi(const vector<int>& deg) { for (int i = 0; i < sz(deg); i++) pq.push({deg[i], i}); vector<vector<int>> adj; while (!pq.empty()) { - auto v = pq.top(); pq.pop(); - if (sz(pq) < v.first) return {}; //impossible + auto [degV, v] = pq.top(); pq.pop(); + if (sz(pq) < degV) return {}; //impossible vector<pair<int, int>> todo; - for (int i = 0; i < v.first; i++) { - auto u = pq.top(); pq.pop(); - adj[v.second].push_back(u.second); - adj[u.second].push_back(v.second); - u.first--; - if (u.first > 0) todo.push_back(u); + for (int i = 0; i < degV; i++) { + auto [degU, v] = pq.top(); pq.pop(); + 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); } return adj; -} +} |
