/** * Return maxflow from ini to end */ int maxflow(int ini, int end) { flow = vi(SZ(dest)); int F = 0; while (MFbfs(ini, end)) while (true) { int tmp = MFdfs(ini, end, INF); F += tmp; if (tmp == 0) break; } return F; }
int maxflow(int ini, int end) { if (_ini != ini || _end != end) { flow = vi(sz(dest)); _ini = ini; _end = end; } while (MFbfs(ini, end)) while (MFdfs(ini, end, INF)); int F = 0; for (int a : adj[ini]) F += flow[a]; return F; }
int MFdfs(int u, int t, int f) { if (u == t) return f; for(int &i = curAdj[u]; i < adj[u].size(); ++i) { int ar = adj[u][i], v = dest[ar]; if (d[v] != d[u]+1 || capres(ar) == 0) continue; int tmpF = MFdfs(v, t, min(f, capres(ar))); if (tmpF) { flow[ar] += tmpF; flow[inv(ar)] -= tmpF; return tmpF; } } return 0; }