Sub topic 11
Finding the Minimum Cut
This chapter assumes you already know the max-flow min-cut theorem, how the residual graph is built, and the adjacency-matrix and adjacency-list Edmonds-Karp implementations from earlier chapters. Here you will turn the final residual graph into a concrete minimum cut. You will also learn how to check that the cut is correct and how to avoid the mistakes that most often break this step.
Why You Want the Cut, Not Just the Number
A maximum flow value tells you how much can get through a network. A minimum cut tells you why no more can get through. It names the edges that form the bottleneck. In practice the cut is often the answer you actually need:
- In network reliability, the cut edges are the smallest set of links whose failure disconnects the source from the sink.
- In image segmentation, the source side and sink side of the cut are the foreground and background pixels.
- In project selection problems, the source side of the cut is the set of projects to take on.
The cut also works as a certificate. If someone hands you a flow of value 23 and a cut of capacity 23, you can check both in linear time and know the flow is optimal. You do not need to trust the algorithm that produced them.
The Recipe
When Ford-Fulkerson (or Edmonds-Karp) stops, there is no augmenting path. That means the sink t cannot be reached from the source s in the residual graph. The recipe follows from this:
- Run a BFS or DFS from
sin the final residual graph. Only follow edges with residual capacity greater than zero. - Let
Sbe the set of vertices you reached, and letTbe every other vertex. - The minimum cut consists of the original edges
(u, v)withuinS,vinT, and capacity greater than zero.
The search costs O(V + E) with adjacency lists or O(V²) with a matrix. Either way, it is cheap next to the max-flow computation.
Why the Reachable Set Is a Minimum Cut
The proof is the second half of the max-flow min-cut theorem. It is worth restating here because it explains every step of the recipe.
Because t was not reached, t is in T. So (S, T) is a valid s-t cut. Now look at the edges that cross it.
- Edges from S to T are saturated. Take an original edge
(u, v)withuinSandvinT. If its flow were below capacity, the residual edgeu -> vwould have positive capacity, and the search would have reachedv. Sof(u, v) = c(u, v). - Edges from T to S carry zero flow. Take an original edge
(v, u)withvinTanduinS. If it carried positive flow, the reverse residual edgeu -> vwould have positive capacity, and again the search would have reachedv. Sof(v, u) = 0.
The net flow across any s-t cut equals the flow value |f|. For this cut, that net flow is the sum of capacities leaving S minus zero. So |f| = c(S, T). No flow can exceed the capacity of any cut, so this flow is maximum and this cut is minimum.
Worked Example
Use the six-node network from the Edmonds-Karp chapter. After the maximum flow of 23 is found, a BFS from node 0 in the residual graph reaches nodes 0, 1, 2, and 4. Nodes 3 and 5 stay unreachable.
The edges crossing from S to T are (1, 3), (4, 3), and (4, 5), with capacities 12 + 7 + 4 = 23. The edge (3, 2) crosses from T to S. It does not count toward the cut capacity, and the proof tells us it must carry zero flow.
The matrix version of the extraction reads the residual matrix that edmonds_karp returns:
from collections import deque
def min_cut(capacity, residual, s):
n = len(capacity)
reachable = [False] * n
reachable[s] = True
queue = deque([s])
while queue:
u = queue.popleft()
for v in range(n):
if not reachable[v] and residual[u][v] > 0:
reachable[v] = True
queue.append(v)
cut_edges = [(u, v) for u in range(n) for v in range(n)
if reachable[u] and not reachable[v] and capacity[u][v] > 0]
return reachable, cut_edges
# Uses capacity and residual from the Edmonds-Karp example
side, edges = min_cut(capacity, residual, 0)
print(edges) # [(1, 3), (4, 3), (4, 5)]
print(sum(capacity[u][v] for u, v in edges)) # 23, equal to the max flowNotice the two different tests. The search follows residual[u][v] > 0, but the cut filter checks capacity[u][v] > 0. Cut edges are saturated, so their residual capacity is zero. Filtering on residual capacity would return an empty list.
Extracting the Cut from the Adjacency-List Implementation
The MaxFlow class from the implementation chapter has no separate residual matrix. Its cap array is the residual graph. Forward edges sit at even indices, and each reverse edge e ^ 1 starts at capacity 0 and gains exactly the flow pushed along e. So the original capacity of a forward edge e is cap[e] + cap[e ^ 1].
from collections import deque
def min_cut_from_maxflow(mf, s):
# mf is a MaxFlow instance on which max_flow(s, t) has already run
reachable = [False] * mf.n
reachable[s] = True
queue = deque([s])
while queue:
u = queue.popleft()
for e in mf.graph[u]:
v = mf.to[e]
if not reachable[v] and mf.cap[e] > 0:
reachable[v] = True
queue.append(v)
cut = []
for e in range(0, len(mf.to), 2): # forward edges only
u, v = mf.to[e ^ 1], mf.to[e]
original = mf.cap[e] + mf.cap[e ^ 1]
if reachable[u] and not reachable[v] and original > 0:
cut.append((u, v, original))
return reachable, cutLooping over even indices only matters. Reverse edges with original capacity 0 would be filtered out anyway. But if you added antiparallel edges u -> v and v -> u separately, each has its own pair, and the even-index loop handles them correctly. Parallel edges each show up as their own cut entry, and their capacities add up.
Common Errors
| Mistake | Symptom | Fix |
|---|---|---|
| Filtering cut edges by residual capacity | Empty cut list | Filter by original capacity |
| Searching the original graph instead of the residual graph | `S` contains every vertex that `s` can reach, often including `t` | Follow edges with residual capacity > 0 |
| Ignoring reverse residual edges in the search | `S` too small; cut capacity exceeds the flow | Follow every residual edge, including reverse ones |
| Adding capacities of edges from T to S | Cut capacity larger than the flow | Count only edges directed from S to T |
| Extracting before the flow is maximum | `t` appears in `S` | Assert `not reachable[t]` |
| Counting flow on cut edges instead of capacity | Correct only by coincidence | Use capacity; it equals the flow only on a true min cut |
A cheap self-check catches most of these. Assert that t is not reachable, and assert that the cut capacity equals the flow value. If either assertion fails, the bug is in the max-flow code or in the extraction, not in the theory.
Edge Cases: The Cut Is Not Always Unique
A network can have several minimum cuts. The forward search from s always finds the one with the smallest source side. You can find the one with the largest source side by searching backward from t. That search finds the vertices that can still reach t through residual edges. Everything else forms the source side.
from collections import deque
def max_source_side(residual, t):
n = len(residual)
reaches_t = [False] * n
reaches_t[t] = True
queue = deque([t])
while queue:
v = queue.popleft()
for u in range(n):
if not reaches_t[u] and residual[u][v] > 0:
reaches_t[u] = True
queue.append(u)
return [not r for r in reaches_t]
print(max_source_side(residual, 5)) # [True, True, True, False, True, False]In the example both searches give S = {0, 1, 2, 4}. When the smallest and largest source sides match, the minimum cut is unique. When they differ, every set that contains the smaller one and is contained in the larger one is not automatically a minimum cut. But both extremes always are, and comparing them is the standard test for uniqueness.
Some other edge cases to keep in mind:
- If
shas no outgoing capacity, the flow is 0,S = {s}, and the cut is empty. - Zero-capacity edges never appear in the cut, which is why the filter checks
capacity > 0. - Floating-point capacities can leave tiny positive residuals such as
1e-12that the search follows. Compare against a small epsilon, or scale the capacities to integers.
Exercises
Exercise
After running max flow, your extraction reports that the sink t is in the reachable set S. What does this tell you, and what should you check?
Show answer
An augmenting path from s to t still exists in the residual graph, so the flow is not maximum. Either the max-flow loop ended too early (for example, the BFS stopped incorrectly or the loop exited after a fixed number of iterations), or the extraction searched a different graph than the final residual graph, such as the original capacities.
Exercise
Network: s -> a with capacity 1, a -> t with capacity 1. Find the maximum flow, the source side from the forward search, and the source side from the backward search from t. Is the minimum cut unique?
Show answer
The maximum flow is 1. Both edges are saturated, so s has no outgoing residual edge and the forward search gives S = {s}, cutting edge (s, a). In the backward search, a cannot reach t because a -> t is saturated, so only t reaches t and the largest source side is {s, a}, cutting edge (a, t). The two sides differ, so the minimum cut is not unique. Both cuts have capacity 1.
Exercise
In the worked example, edge (3, 2) goes from T to S. Without looking at the flow values, explain why it must carry zero flow in every maximum flow.
Show answer
If (3, 2) carried positive flow, the residual graph would have the reverse edge 2 -> 3 with positive capacity. Node 2 is in S, so the search would reach node 3, which contradicts 3 being in T. The minimum cut here is unique, so every maximum flow gives the same S, and the argument holds for all of them.