MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / max_flow

Method max_flow

code/graph/edmonds_karps.cpp:14–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12 e.push_back(edge(v,uv,head[u])); head[u]=(int)size(e)-1;
13 e.push_back(edge(u,vu,head[v])); head[v]=(int)size(e)-1;}
14 int max_flow(int s, int t, bool res=true) {
15 e_store = e;
16 int l, r, v, f = 0;
17 while (true) {
18 memset(d, -1, n*sizeof(int));
19 memset(p, -1, n*sizeof(int));
20 l = r = 0, d[q[r++] = s] = 0;
21 while (l < r)
22 for (int u = q[l++], i = head[u]; i != -1; i=e[i].nxt)
23 if (e[i].cap > 0 &&
24 (d[v = e[i].v] == -1 || d[u] + 1 < d[v]))
25 d[v] = d[u] + 1, p[q[r++] = v] = i;
26 if (p[t] == -1) break;
27 int at = p[t], x = INF;
28 while (at != -1)
29 x = min(x, e[at].cap), at = p[e[at^1].v];
30 at = p[t], f += x;
31 while (at != -1)
32 e[at].cap -= x, e[at^1].cap += x, at = p[e[at^1].v]; }
33 if (res) reset();
34 return f; } };
35// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected