Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ch9/mcmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class min_cost_max_flow {
auto &[v, cap, flow, cost] = EL[AL[u][i]];
if (!vis[v] && d[v] == d[u]+cost) { // in current layer graph
if (ll pushed = DFS(v, t, min(f, cap-flow))) {
total_cost += pushed * cost;
flow += pushed;
auto &[rv, rcap, rflow, rcost] = EL[AL[u][i]^1]; // back edge
rflow -= pushed;
Expand Down Expand Up @@ -86,8 +85,10 @@ class min_cost_max_flow {
ll mf = 0; // mf stands for max_flow
while (SPFA(s, t)) { // an O(V^2*E) algorithm
last.assign(V, 0); // important speedup
while (ll f = DFS(s, t)) // exhaust blocking flow
while (ll f = DFS(s, t)) { // exhaust blocking flow
mf += f;
total_cost += f * d[t];
}
}
return {mf, total_cost};
}
Expand Down