@@ -72,23 +72,25 @@ template <class Cap, class Cost> struct mcf_graph {
72
72
std::vector<Cost> dual (_n, 0 ), dist (_n);
73
73
std::vector<int > pv (_n), pe (_n);
74
74
std::vector<bool > vis (_n);
75
+ struct Q {
76
+ Cost key;
77
+ int to;
78
+ bool operator <(Q r) const { return key > r.key ; }
79
+ };
80
+ std::vector<Q> que;
75
81
auto dual_ref = [&]() {
76
82
std::fill (dist.begin (), dist.end (),
77
83
std::numeric_limits<Cost>::max ());
78
- std::fill (pv.begin (), pv.end (), -1 );
79
- std::fill (pe.begin (), pe.end (), -1 );
80
84
std::fill (vis.begin (), vis.end (), false );
81
- struct Q {
82
- Cost key;
83
- int to;
84
- bool operator <(Q r) const { return key > r.key ; }
85
- };
86
- std::priority_queue<Q> que;
85
+ que.clear ();
86
+
87
87
dist[s] = 0 ;
88
- que.push (Q{0 , s});
88
+ que.push_back (Q{0 , s});
89
+ std::push_heap (que.begin (), que.end ());
89
90
while (!que.empty ()) {
90
- int v = que.top ().to ;
91
- que.pop ();
91
+ int v = que.front ().to ;
92
+ std::pop_heap (que.begin (), que.end ());
93
+ que.pop_back ();
92
94
if (vis[v]) continue ;
93
95
vis[v] = true ;
94
96
if (v == t) break ;
@@ -105,7 +107,8 @@ template <class Cap, class Cost> struct mcf_graph {
105
107
dist[e.to ] = dist[v] + cost;
106
108
pv[e.to ] = v;
107
109
pe[e.to ] = i;
108
- que.push (Q{dist[e.to ], e.to });
110
+ que.push_back (Q{dist[e.to ], e.to });
111
+ std::push_heap (que.begin (), que.end ());
109
112
}
110
113
}
111
114
}
0 commit comments