A · Legendary · 14 min

Max Flow and Min Cut

Push as much as possible from s to t through capacitated edges. Ford–Fulkerson finds augmenting paths; min-cut equals max-flow. Most 'assignment' and 'edge-disjoint paths' problems are a reduction, not a new algorithm.

A flow network is a directed graph with capacities. A flow assigns each edge a value ≤ capacity, conserves at every vertex except source s and sink t. Max flow is the maximum net leaving s.

Min cut: a partition (S, T) with s∈S, t∈T; capacity is the sum of edges S→T. The theorem: max flow = min cut. That is why 'minimum edges to disconnect' and 'maximum assignments' share a template.

CSES Download Speed (max flow), Police Chase (min cut), School Dance (bipartite matching = flow). Rare on CF Div. 2; expected in OI. Dinic is the contest implementation; this lesson uses Edmonds–Karp (BFS augmenting paths) so the invariant is visible.

Edmonds–Karp on an adjacency matrix (n is tiny here)js
function maxFlow(cap, s, t) {
  const n = cap.length;
  const res = cap.map((row) => row.slice());
  function bfs() {
    const par = Array(n).fill(-1);
    par[s] = s;
    const q = [s];
    for (let qi = 0; qi < q.length; qi++) {
      const u = q[qi];
      for (let v = 0; v < n; v++) {
        if (par[v] === -1 && res[u][v] > 0) {
          par[v] = u;
          q.push(v);
        }
      }
    }
    return par;
  }
  let flow = 0;
  let par;
  while ((par = bfs()) && par[t] !== -1) {
    let add = Infinity;
    for (let v = t; v !== s; v = par[v]) add = Math.min(add, res[par[v]][v]);
    for (let v = t; v !== s; v = par[v]) {
      res[par[v]][v] -= add;
      res[v][par[v]] += add;
    }
    flow += add;
  }
  return flow;
}

TRACE

s=0, t=3. Edges 0→1:2, 0→2:2, 1→3:1, 2→3:2, 1→2:1.

Path 0-1-3

Bottleneck 1. Send 1. Residual 1→0 and 3→1 appear.

flow = 1

1 / 3

CHECK

Bipartite matching (n left, m right, edges = possible pairs). How do you build the network?

CHECK

When is max flow the wrong hammer?

Checks 0/2

Next lesson