From bdfd09400742be9be45359d69d2dc98aa55e86b9 Mon Sep 17 00:00:00 2001 From: "ACHERONMIRROR\\ArtemiszeN" Date: Sat, 10 Feb 2024 15:04:35 +0800 Subject: [PATCH] Add min cost flow functionality to ch9/mcmf.cpp Param flow_limit can be ignored for normal mcmf usage. --- ch9/mcmf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ch9/mcmf.cpp b/ch9/mcmf.cpp index 9335e78..dda5971 100644 --- a/ch9/mcmf.cpp +++ b/ch9/mcmf.cpp @@ -82,11 +82,11 @@ class min_cost_max_flow { if (!directed) add_edge(v, u, w, c); // add again in reverse } - pair mcmf(int s, int t) { + pair mcmf(int s, int t, ll flow_limit = (ll)1e18) { ll mf = 0; // mf stands for max_flow - while (SPFA(s, t)) { // an O(V^2*E) algorithm + while (SPFA(s, t) && mf < flow_limit) { // 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, flow_limit - f)) // exhaust blocking flow mf += f; } return {mf, total_cost};