Rare
 0/9

Minimum Cut

Author: Benjamin Qi

?

Focus Problem – read through this problem before continuing!

Resources

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

Resources
CPCSlides from "Algorithm Design." Min-Cut Max-Flow Theorem, applications of flow / min cut.
CPHBrief descriptions of flow / min cut applications.

Solution - Coin Grid

This problem asks us for the 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) { N = _N; adj.rsz(N), cur.rsz(N); }
/// void reset() { trav(e,eds) e.flo = 0; }
void ae(int u, int v, F cap, F rcap = 0) { assert(min(cap,rcap) >= 0);
adj[u].pb(sz(eds)); eds.pb({v,0,cap});
adj[v].pb(sz(eds)); eds.pb({u,0,rcap});
}

Path Covers

StatusSourceProblem NameDifficultyTagsSolution
KattisHardView Solution

https://www.facebook.com/codingcompetitions/hacker-cup/2015/round-3/problems/C

Problems

StatusSourceProblem NameDifficultyTagsSolution
CSESEasyView Solution
Old GoldEasy
Show Tags

Max Flow

External Sol
CSANormalCheck CSA
CFNormalCheck CF
CFNormalCheck CF
CFHardCheck CF
ACHardCheck AC

Give Us Feedback on Minimum Cut!

Module Progress: