Resources

The resources below include many clever applications of min cut, including the Closure Problem.

Resources
CPC

Slides from "Algorithm Design." Min-Cut Max-Flow Theorem, applications of flow / min cut.

Min-Cut Max-Flow Theorem

Given a flow network with source ss and sink tt, an ss-tt cut is a partition of the vertices into two sets SS and TT with sSs \in S and tTt \in T. Its capacity is the total capacity of the edges crossing from the source side to the sink side:

cap(S,T)=e:STc(e).\operatorname{cap}(S, T) = \sum_{e:\, S \to T} c(e).

(Edges pointing the other way, from TT to SS, contribute nothing.) Cutting all of these edges disconnects ss from tt, so intuitively the capacity of a cut is an upper bound on how much flow can get from ss to tt. Indeed, for any flow ff and any cut (S,T)(S, T),

val(f)=e:STf(e)e:TSf(e)e:STc(e)=cap(S,T),\operatorname{val}(f) = \sum_{e:\, S \to T} f(e) - \sum_{e:\, T \to S} f(e) \le \sum_{e:\, S \to T} c(e) = \operatorname{cap}(S, T),

where val(f)\operatorname{val}(f) is the total flow from ss to tt. So every flow is bounded by every cut.

Here is an illustration of a sts-t cut: red nodes are in SS, and blue nodes are in TT. Importantly, there is no need for SS and TT to be connected: the only requirement is that sSs \in S and tTt \in T. The capacity of this cut is the sum of the capacities underlined in green, 2+1=32 + 1 = 3. The flow across this cut derives from the numbers underlined in yellow, 21+1=22 - 1 + 1 = 2, which we note is equivalent to the actual sts-t flow, val(f)\operatorname{val}(f). Also note that in this instance, the flow across the cut (22) is less than its capacity (33). However, if we instead choose S={s}S = \{s\} and T=V{s}T = V \setminus \{s\}, the flow across the cut (22) and its capacity (22) will be equal.

The min-cut max-flow theorem states that in general, we can always achieve such equality:

The maximum value of an ss-tt flow equals the minimum capacity of an ss-tt cut.

To show tightness, we just need to construct a flow ff and cut (S,T)(S, T) such that val(f)=cap(S,T)\operatorname{val}(f) = \operatorname{cap}(S, T). To do this, we will let ff be any maximum flow, then use the fact that ff cannot have any remaining augmenting paths to construct a minimum capacity (S,T)(S, T) cut. In fact, it turns out this cut can be constructed by letting SS be the set of nodes reachable from SS in the residual graph (and TT be the set of all other nodes, i.e. VSV - S). To see why this is the case, consider the following diagram:

By definition, the red edges must be saturated to capacity, otherwise nodes in SS would be able to reach nodes in TT. Similarly, the blue edges must have 0 flow. Therefore, the flow across this cut equals the capacity of this cut, as desired.

Minimum Node Covers

Focus Problem – try your best to solve this problem before continuing!

Resources
CPH

brief mentions of Hall's Theorem, Konig's Theorem

Solution - Coin Grid

This problem asks us to find a minimum node cover of a bipartite graph. Construct a flow graph with vertices labeled 02N+10\ldots 2N+1, source 00, sink 2N+12N+1, and the following edges:

  • Edges from 0i0\to i with capacity 11 for each 1iN1\le i\le N. Cutting the ii-th such edge corresponds to choosing the ii-th row.
  • Edges from N+i2N+1N+i\to 2N+1 with capacity 11 for each 1iN1\le i\le N. Cutting the ii-th such edge corresponds to choosing the ii-th column.
  • If there exists a coin in (r,c)(r,c) add an edge from rN+cr\to N+c with capacity \infty.

First we find a max flow, which tells us the number of edges with capacity 1 we need to cut. To find the min cut itself, BFS from the source once more time. Edges (a,b)(a,b) connecting vertices that are reachable from the source (lev[a] != -1) to vertices that aren't (lev[b] == -1) are part of the minimum cut. In this case, each of these edges must be of the form (0,i)(0,i) or (i+N,2N+1)(i+N,2N+1) for 1iN1\le i\le N. Each cut edge corresponds to a row or column we remove coins from.

Note that edges of the form rN+cr\to N+c can't be cut because they have capacity \infty.

struct Dinic { // flow template
using F = ll; // flow type
struct Edge {
int to;
F flo, cap;
};
int N;
V<Edge> eds;
V<vi> adj;
void init(int _N) {

Minimum Path Covers

Focus Problem – try your best to solve this problem before continuing!

Resources
CPH

brief mentions of node-disjoint and general path covers, Dilworth's theorem

Wikipedia

proof via Konig's theorem

Solution - The Wrath of Kahn

Ignore all vertices of GG that can never be part of SS. Then our goal is to find the size of a maximum antichain in the remaining graph, which as mentioned in CPH is just an instance of minimum path cover.

TopoSort<500> T;
int n, m;
bool link[500][500];
vi out[500];
Dinic<1005> D;
int main() {
setIO();
re(n, m);
F0R(i, m) {

Problems

StatusSourceProblem NameDifficultyTags
CSESEasy
Old GoldEasy
Show TagsMax Flow
CSANormal
CFNormal
CFNormal
CFHard
ACHard
FHCHard

Module Progress:

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!