diff --git a/atcoder/mincostflow.hpp b/atcoder/mincostflow.hpp index f7bfc9f..d532aac 100644 --- a/atcoder/mincostflow.hpp +++ b/atcoder/mincostflow.hpp @@ -72,23 +72,25 @@ template struct mcf_graph { std::vector dual(_n, 0), dist(_n); std::vector pv(_n), pe(_n); std::vector vis(_n); + struct Q { + Cost key; + int to; + bool operator<(Q r) const { return key > r.key; } + }; + std::vector que; auto dual_ref = [&]() { std::fill(dist.begin(), dist.end(), std::numeric_limits::max()); - std::fill(pv.begin(), pv.end(), -1); - std::fill(pe.begin(), pe.end(), -1); std::fill(vis.begin(), vis.end(), false); - struct Q { - Cost key; - int to; - bool operator<(Q r) const { return key > r.key; } - }; - std::priority_queue que; + que.clear(); + dist[s] = 0; - que.push(Q{0, s}); + que.push_back(Q{0, s}); + std::push_heap(que.begin(), que.end()); while (!que.empty()) { - int v = que.top().to; - que.pop(); + int v = que.front().to; + std::pop_heap(que.begin(), que.end()); + que.pop_back(); if (vis[v]) continue; vis[v] = true; if (v == t) break; @@ -105,7 +107,8 @@ template struct mcf_graph { dist[e.to] = dist[v] + cost; pv[e.to] = v; pe[e.to] = i; - que.push(Q{dist[e.to], e.to}); + que.push_back(Q{dist[e.to], e.to}); + std::push_heap(que.begin(), que.end()); } } }