TExcelTAD
Home › Graph Algorithms › The Max-Flow Min-Cut Theorem

The Max-Flow Min-Cut Theorem

Every cut's capacity bounds every flow's value from above, as the previous lesson showed. The max-flow min-cut theorem (Ford and Fulkerson; Elias, Feinstein and Shannon; both 1956) says the bound is always reached: the largest flow equals the smallest cut. It is the reason the augmenting-path method is correct, it tells us how to certify that a flow is maximum, and it turns many "minimum cut" questions (how many links must fail to disconnect a network? which pixels belong to the foreground?) into flow computations. It is also a first example of duality, which the linear programming course develops in general.

The theorem

Theorem. For a flow ff in a flow network GG with source ss and sink tt, the following are equivalent:

  1. ff is a maximum flow;
  2. the residual network GfG_f contains no augmenting path;
  3. ∣f∣=c(S,T)\lvert f \rvert = c(S, T) for some cut (S,T)(S, T).
Proof

(1) implies (2). If GfG_f had an augmenting path pp, augmenting along it would give a flow of value ∣f∣+cf(p)>∣f∣\lvert f \rvert + c_f(p) > \lvert f \rvert, so ff would not be maximum.

(2) implies (3). Let SS be the set of vertices reachable from ss in GfG_f, and T=V∖ST = V \setminus S. Then s∈Ss \in S, and t∉St \notin S because there is no augmenting path, so (S,T)(S, T) is a cut. Look at any u∈Su \in S and v∈Tv \in T:

  • If (u,v)∈E(u, v) \in E, then f(u,v)=c(u,v)f(u, v) = c(u, v): otherwise the residual edge (u,v)(u, v) would exist and vv would be reachable.
  • If (v,u)∈E(v, u) \in E, then f(v,u)=0f(v, u) = 0: otherwise the backward residual edge (u,v)(u, v) would exist and vv would be reachable.

So every edge from SS to TT is full and every edge from TT to SS is empty, and by the lemma on cuts

∣f∣=f(S,T)=∑u∈S∑v∈Tc(u,v)−0=c(S,T)\lvert f \rvert = f(S, T) = \sum_{u \in S} \sum_{v \in T} c(u, v) - 0 = c(S, T)

(3) implies (1). Every flow f′f' satisfies ∣f′∣≤c(S,T)=∣f∣\lvert f' \rvert \le c(S, T) = \lvert f \rvert, so ff is maximum.

Two consequences are worth stating separately:

  • Max flow = min cut. The value of a maximum flow equals the minimum capacity of a cut. A maximum flow and a minimum cut certify each other: anyone can check that the flow is valid, that the cut has the same number as its capacity, and conclude that both are optimal.
  • Finding a minimum cut. After computing a maximum flow, the set SS of vertices reachable from ss in GfG_f gives a minimum cut, at the cost of one more search, O(V+E)O(V + E).

Finding the cut

The program runs a short augmenting-path algorithm on the network of Flow Networks (BFS for each path, as in the animation there), takes the residual reachable set as SS, and checks the result against all 16 cuts.

python · try it yourself
from collections import deque
from itertools import combinations

cap = {("S", "A"): 10, ("S", "B"): 7, ("A", "B"): 4, ("A", "C"): 5, ("B", "D"): 9,
       ("C", "B"): 3, ("C", "T"): 8, ("D", "C"): 4, ("D", "T"): 6}
V = "SABCDT"
flow = {e: 0 for e in cap}

def residual_neighbours(u):
    for (a, b), c in cap.items():
        if a == u and c - flow[(a, b)] > 0:
            yield b
        if b == u and flow[(a, b)] > 0:
            yield a

def reachable(s):
    prev, q = {s: None}, deque([s])
    while q:
        u = q.popleft()
        for v in sorted(residual_neighbours(u)):
            if v not in prev:
                prev[v] = u; q.append(v)
    return prev

while "T" in (prev := reachable("S")):
    path, v = ["T"], "T"
    while prev[v]:
        v = prev[v]; path.append(v)
    path.reverse()
    def rc(u, v):
        return cap[(u, v)] - flow[(u, v)] if (u, v) in cap else flow[(v, u)]
    b = min(rc(u, v) for u, v in zip(path, path[1:]))
    for u, v in zip(path, path[1:]):
        if (u, v) in cap: flow[(u, v)] += b
        else: flow[(v, u)] -= b
    print("augment", "".join(path), "by", b)

value = flow[("S", "A")] + flow[("S", "B")]
S = set(reachable("S"))
crossing = [(u, v) for (u, v) in cap if u in S and v not in S]
print("max flow:", value)
print("residual reachable set S:", sorted(S), " cut edges:", crossing,
      " capacity:", sum(cap[e] for e in crossing))
print("edges from T back to S carry flow:", [flow[(u, v)] for (u, v) in cap if v in S and u not in S])

caps = {}
for k in range(5):
    for extra in combinations("ABCD", k):
        side = {"S", *extra}
        caps["".join(sorted(side))] = sum(c for (u, v), c in cap.items() if u in side and v not in side)
best = min(caps.values())
print("minimum over all 16 cuts:", best, " achieved by", [s for s, c in caps.items() if c == best])
augment SACT by 5
augment SBDT by 6
augment SBDCT by 1
augment SABDCT by 2
max flow: 14
residual reachable set S: ['A', 'B', 'S']  cut edges: [('A', 'C'), ('B', 'D')]  capacity: 14
edges from T back to S carry flow: [0]
minimum over all 16 cuts: 14  achieved by ['ABS', 'ABCDS']

The residual reachable set is {S,A,B}\{S, A, B\}. The edges A→CA \to C and B→DB \to D leaving it are full (5 and 9), the edge C→BC \to B coming back is empty, and the capacity 5+9=145 + 9 = 14 equals the flow. The brute force confirms 14 as the minimum and finds a second minimum cut, {S,A,B,C,D}\{S, A, B, C, D\}, crossed by the two edges into TT. Minimum cuts need not be unique; the residual set always gives the one closest to ss.

Menger's theorem: disjoint paths and cuts

Give every edge capacity 1. An integer flow of value kk then decomposes into kk paths from ss to tt that share no edge, and a cut of capacity kk is a set of kk edges whose removal disconnects tt from ss. Max-flow min-cut becomes Menger's theorem: the maximum number of edge-disjoint paths from ss to tt equals the minimum number of edges whose removal disconnects them. In network terms, it is how many link failures a connection can survive. The program computes both numbers for a small network and prints the paths, found by following unit flows.

python · try it yourself
from collections import deque

links = [("S", "A"), ("S", "B"), ("S", "C"), ("A", "D"), ("B", "D"), ("B", "E"), ("C", "E"),
         ("D", "T"), ("E", "T"), ("A", "B")]
cap = {e: 1 for e in links}
flow = {e: 0 for e in links}

def bfs_path():
    prev, q = {"S": None}, deque(["S"])
    while q:
        u = q.popleft()
        nbrs = [(b, "f") for (a, b) in links if a == u and flow[(a, b)] < 1] + \
               [(a, "b") for (a, b) in links if b == u and flow[(a, b)] > 0]
        for v, kind in sorted(nbrs):
            if v not in prev:
                prev[v] = (u, kind); q.append(v)
    return prev

count = 0
while "T" in (prev := bfs_path()):
    v = "T"
    while prev[v]:
        u, kind = prev[v]
        if kind == "f": flow[(u, v)] += 1
        else: flow[(v, u)] -= 1
        v = u
    count += 1

paths = []
for _ in range(count):                         # peel off one path per unit of flow
    p, u = ["S"], "S"
    while u != "T":
        v = next(b for (a, b) in links if a == u and flow[(a, b)] == 1)
        flow[(u, v)] = 0
        p.append(v); u = v
    paths.append("".join(p))
print("edge-disjoint paths:", count, paths)
for e in links:                                # restore the maximum flow to read off the cut
    flow[e] = 0
for p in paths:
    for u, v in zip(p, p[1:]):
        flow[(u, v)] = 1
reach = set(bfs_path())
cut = [f"{a}{b}" for (a, b) in links if a in reach and b not in reach]
print("residual reachable set:", sorted(reach), " cut edges:", cut)
edge-disjoint paths: 2 ['SADT', 'SBET']
residual reachable set: ['A', 'B', 'C', 'D', 'E', 'S']  cut edges: ['DT', 'ET']

Three edges leave SS, but only two enter TT, so at most two edge-disjoint paths can exist, and the program finds two. The residual reachable set is everything except TT, and the cut it defines is exactly the two edges into TT: if both fail, TT is cut off, while any single failure leaves one of the two paths intact. Menger's theorem also has a vertex version (internally vertex-disjoint paths versus vertex cuts), which follows by giving every vertex capacity 1 with the splitting trick of Flow Networks.

Test yourself

Which three statements does the max-flow min-cut theorem prove equivalent?

  1. ff is maximum; GfG_f has no augmenting path; ∣f∣=c(S,T)\lvert f \rvert = c(S, T) for some cut
  2. ff is integral; GG is acyclic; ff is unique
  3. ff is maximum; GG is bipartite; every edge is full
  4. ff is maximum; every cut has capacity ∣f∣\lvert f \rvert; GfG_f is empty

After a maximum flow is computed, how do you find a minimum cut?

  1. Take the edges with the largest capacities
  2. Let SS be the set of vertices reachable from ss in the residual network; (S,V∖S)(S, V \setminus S) is a minimum cut
  3. Remove all full edges
  4. Run Kruskal's algorithm

In a network with unit capacities, the maximum flow from ss to tt is 3. What does Menger's theorem say?

  1. There are exactly 3 paths from ss to tt
  2. There are 3 edge-disjoint paths from ss to tt, and removing some 3 edges disconnects tt from ss
  3. Every vertex has degree 3
  4. Any 3 edges disconnect tt