Topic E: Max Flow



Section 1: The Max Flow Problem

This section introduces the max flow problem.

Objectives. After learning this material, you should be able to:

Motivation and input

We have already looked at finding paths in a graph. What if we want to route a large amount of traffic across a graph, such as packets across a computer network? In this case, the traffic may need to take multiple routes at once. Each edge of the network can only handle so much traffic at once -- the capacity of that edge. We'd like to figure out how to route the traffic so as to get the most possible across.

In the max flow problem, the input consists of:

We can also think of the capacity function as nonnegative edge weights. We extend $c$ to be a function on all pairs of vertices, by defining $c(u,v) = 0$ if $(u,v) \not\in E$. We will also make the following simplifying assumption, which isn't necessary, but makes our lives a bit easier:

Assumption: no anti-parallel edges. We assume that if $(u,v) \in E$, then $(v,u) \not\in E$. In other words, there is only one edge between any pair of vertices.

An example graph. Source s, sink t, and capacities on the edges: c(s,v)=4, c(s,w)=9, c(w,v)=7, c(w,x)=3, c(v,x)=5, c(v,t)=2, c(x,t)=9.

Figure 1.

Valid flows

Given the input, a potential solution is any method of routing flow from $s$ to $t$. But what does that mean, exactly? A function $f: V \times V \to \mathbb{R}_{\geq 0}$ is called a flow, and the flow is valid if:

We illustrate the current flow compared to the capacity of the edge using the notation "flow/capacity", e.g. 6/10.

An edge with capacity 10 and flow 6, represented as 6/10.


Exercise 1.

On the example graph of Figure 1 above, which of the following flows are valid? If invalid, indicate whether the flow or capacity constraint is violated. From now on, we will label each edge $(u,v)$ with a label of the form 5/9, where here $5$ represents $f(u,v)$ and 9 represents $c(u,v)$. We have also put the flows in blue here for added emphasis.

f(s,v)=2, f(s,w)=3, s(v,x)=1, s(v,t)=2, s(w,v)=1, s(w,x)=2, s(x,t)=3.

Part a.

f(s,v)=2, f(s,w)=3, s(v,x)=3, s(v,t)=2, s(w,v)=3, s(w,x)=2, s(x,t)=5.

Part b.

f(s,v)=2, f(s,w)=5, s(v,x)=3, s(v,t)=4, s(w,v)=3, s(w,x)=2, s(x,t)=3.

Part c.



Solution.
  • Part a: valid.
  • Part b: invalid. The flow constraint at $w$ is violated: the total flow in is 3, but the total flow out is 5.
  • Part c: invalid. The capacity constraint on $(v,t)$ is violated: $c(v,t) = 2$, but $f(v,t) = 4$.

Max flow

Given a flow $f$, we define the amount of flow, written $|f|$ for short, to be the following quantity:

$|f| = \sum_{v \in V} f(v,t) - \sum_{w \in V} f(t,w)$.

In other words, the total amount of flow $|f|$ is the net flow into the sink $t$.

In the max flow problem, the output is:

Exercise 2.

On the example graph of Figure 1, what is the max flow amount and what is the flow?

Solution.

Here is a max flow $f$. The amount of $|f| = 10$. There are other slightly different flows that also have value $10$ (can you find them?).

f(s,v)=4, f(s,w)=6, f(v,t)=2, f(v,x)=5, f(w,v)=3, f(w,x)=3, f(x,t)=8



Section 2: Ford-Fulkerson

This section describes the Ford Fulkerson framework for solving max flow.

Objectives. After learning this material, you should be able to:

Breaking and fixing the natural approach

Here's a very natural algorithm that almost works:

Unfortunately, this doesn't always work to find the max flow! We need the ability to "cancel" use of an edge and backtrack on some decisions. Luckily, it turns out that we can achieve this by pretending to send flow "backward" along that edge, which has the effect of cancelling out the forward flow. Here's an example:

c(s,x)=4, c(s,y)=5, c(x,t)=5, c(y,x)=7, c(y,t)=3

We first send 5 units of flow along the path $s,y,x,t$. This results in the following flow.

f(s,y)=5, f(y,x)=5, f(x,t)=5. Other edges have flow zero.

Now, we are stuck, because there is no path from $s$ to $t$ along which we can send more flow. But we have not found the max flow yet. The way out is to send 3 units of flow along the path $s,x,y,t$. Even though $(x,y)$ is not an edge in the graph, we can "send" flow along this edge by reducing the current amount of flow.

f(s,y)=5, f(s,x)=3, f(y,x)=2, f(x,t)=5, f(y,t)=3

Another way to think of what happened is that we took 3 units of flow along $(y,x)$ and re-routed it to $(y,t)$. To replace that 3 units of flow at $x$, we brought over 3 units of flow along $(s,x)$.

This idea leads to the Ford-Fulkerson framework for max-flow algorithms. First, we need to make some useful definitions in order to fully define the algorithm.

Residual capacity function and residual graph

The residual capacity function $r_f: V \times V \to \mathbb{R}_+$ is defined as follows:

The residual graph $G_f = (V, E_f)$ is a graph where there is an edge $(u,v) \in E_f$ if $r_f(u,v) > 0$, otherwise $(u,v) \not\in E_f$. It is important that if $r_f(u,v) = 0$, then the edge $(u,v)$ is NOT in $E_f$. We will draw $r_f$ as edge weights on $G_f$, and we'll sometimes refer to both together as the "residual graph".

Illustration of residual capacity and residual flow on a single edge.

We can describe these operations more formally as follows.


1  residuals(G, c, f):
2      // G = (V,E) is a directed graph, c is a capacity function, f is a flow
3      let Ef be an empty set
4      for each edge (u,v) in G:
5          set rf(u,v) = c(u,v) - f(u,v)
6          if rf(u,v) > 0:
7              add (u,v) to Ef
8          set rf(v,u) = f(u,v)
9          if rf(v,u) > 0:
10             add (v,u) to Ef
11     return rf, (V,Ef)
Exercise 3.

Consider the following input graph and flow. Draw the residual graph. To do so, follow these instructions:

  1. For the residual capacity function, calculate the residual capacity $r_f(u,v)$ of each edge $(u,v)$ as well as its reverse $(v,u)$.
  2. For the residual graph, draw a copy of the graph's vertices. For every pair $(u,v)$ where $r_f(u,v) > 0$, draw an edge from $u$ to $v$. Label the edge with its residual capacity.
  3. Important: if $r_f(u,v) = 0$, then edge $(u,v)$ should NOT be included in the graph.
c(s,x)=4, c(s,y)=5, c(x,t)=5, c(y,x)=7, c(y,t)=3. f(s,y)=5, f(y,x)=5, f(x,t)=5. Other edges have flow zero.
Solution. rf(s,x)=4, rf(y,s)=5, rf(x,y)=2, rf(y,x)=5, rf(t,x)=5, rf(y,t)=3.

Notice the differences between which edges are present in the residual graph, compared to the original graph:

Augmenting paths

The last concept we need is an augmenting path: a path $s=v_1,\dots,v_k=t$ from $s$ to $t$ in the residual graph. Note that because this is a path in the residual graph, we have that $r_f(v_i, v_{i+1}) > 0$ for every edge along this path. In other words, we can send more flow along every edge in this path.


// Subroutine 1: Augment a flow along a path
1  augment(G, f, rf, path):
2      // G is the input graph, f is a flow, rf is residual flow
3      // path goes from s to t in the residual graph
4      let d = min( rf(u,v) for (u,v) in path )
5      for each edge (u,v) in path:
6          if (u,v) in G:
7              f(u,v) += d
8          else:              // here, (v,u) must be in G
9              f(v,u) -= d
10     return f and d
Exercise 4.

Find an augmenting path in the residual graph of the previous exercise. Then, augment the flow along the path. To do so, follow these instructions:

  1. Give a path from $s$ to $t$ in the residual graph.
  2. Give the amount we can augment, $d$.
  3. Give the updated flow $f$ after augmenting. To do so, draw the graph and label each edge with flow/capacity.
Solution.
  1. $s,x,y,t$. Note: this is the only path.
  2. The amount is $3$. Note: $r_f(s,x) = 4, r_f(x,y) = 5, r_f(y,t) = 3$, so the minimum is $3$.
  3. Here is the updated flow:
Label 3/4 on (s,x). Label 5/5 on (s,y). Label 2/7 on (y,x). Label 5/5 on (x,t). Label 3/3 on (y,t).

Ford-Fulkerson Framework

The Ford-Fulkerson Framework is the following algorithmic framework:


// Algorithmic Framework 1: Ford-Fulkerson
1  fordfulkerson(G, c):
2      // G is a directed graph, c is a capacity function
3      let f(u,v) = 0 for all vertex pairs u,v
4      repeat:
5          let Gf and rf = residuals(G, c, f)
6          find a path from s to t in Gf
7          let f and d = augment(G, f, rf, path)
8          if d == 0:
9              return f

Notice that line 6, where we find a path, is underspecified. How do we choose the path? There turn out to be several reasonable choices for this step. Because of this, Ford-Fulkerson is called a framework rather than an algorithm. To make it an algorithm, we need to specify how to implement line 6.

Exercise 5.

Run the Ford-Fulkerson framework on the example graph of Figure 1, reproduced here. You can use any method to find a path in the residual graph.

An example graph. Source s, sink t, and capacities on the edges: c(s,v)=4, c(s,w)=9, c(w,v)=7, c(w,x)=3, c(v,x)=5, c(v,t)=2, c(x,t)=9.

Figure 1 (reproduced).

In each round, give the following things:

Example Solution.

There are multiple possible answers, depending on the path chosen.

First round:

Flow: $|f| = 0$.

flow zero everywhere

Residual flow:

Residual capacity equals original capacity on edges of the graph.

Path: $s,v,t$. Amount: $2$.


Second round:

Flow: $|f| = 2$.

Label 2/4 on (s,v). Label 0/9 on (s,w). Label 0/7 on (w,v). Label 2/2 on (v,t). Label 0/5 on (v,x). Label 0/3 on (w,x). Label 0/9 on (x,t).

Residual flow:

2 on (s,v), 2 on (v,s). 9 on (s,w). 7 on (w,v). 2 on (t,v). 5 on (v,x). 3 on (w,x). 9 on (x,t).

Path: $s,v,x,t$. Amount: $2$.


Third round:

Flow: $|f| = 4$.

Label 4/4 on (s,v). Label 0/9 on (s,w). Label 0/7 on (w,v). Label 2/2 on (v,t). Label 2/5 on (v,x). Label 0/3 on (w,x). Label 2/9 on (x,t).

Residual flow:

4 on (v,s). 9 on (s,w). 7 on (w,v). 2 on (t,v). 3 on (v,x), 2 on (x,v). 3 on (w,x). 7 on (x,t), 2 on (t,x).

Path: $s,w,x,t$. Amount: $3$.


Fourth round:

Flow: $|f| = 7$.

Label 4/4 on (s,v). Label 3/9 on (s,w). Label 0/7 on (w,v). Label 2/2 on (v,t). Label 2/5 on (v,x). Label 3/3 on (w,x). Label 5/9 on (x,t).

Residual flow:

4 on (v,s). 6 on (s,w), 3 on (w,s). 7 on (w,v). 2 on (t,v). 3 on (v,x), 2 on (x,v). 3 on (x,w). 4 on (x,t), 5 on (t,x).

Path: $s,w,v,x,t$. Amount: $3$.


Fifth round:

Flow: $|f| = 10$.

Label 4/4 on (s,v). Label 6/9 on (s,w). Label 3/7 on (w,v). Label 2/2 on (v,t). Label 5/5 on (v,x). Label 3/3 on (w,x). Label 8/9 on (x,t).

Residual flow:

4 on (v,s). 3 on (s,w), 6 on (w,s). 4 on (w,v), 3 on (v,w). 2 on (t,v). 5 on (x,v). 3 on (x,w). 1 on (x,t), 8 on (t,x).

Path: no path exists from $s$ to $t$. Stop.


Final amount of flow: $|f| = 10$.




Section 3: Correctness and Min Cut

This section proves Ford Fulkerson correct using the concept of the min $s-t$ cut.

Objectives. After learning this material, you should be able to:

Min cut

To prove that Ford Fulkerson is correct, we'll need a non-obvious, very mathematically nice strategy. The idea is that the maximum flow is limited by bottlenecks in the graph, where no more flow can squeeze through. If there is a bottleneck where the total capacity to squeeze through is 10, then the max the flow could possibly be is 10. The tricky part is that a bottleneck could contain multiple edges.

A $s-t$ cut in a directed graph $G = (V,E)$ is a partition of the vertices into two sets, $S$ and $T$, such that $s \in S$ and $t \in T$.

Given a capacity function $c$, the capacity of an $s-t$ cut $(S,T)$ is the total capacity of edges that cross from $S$ to $T$, which is

\[ K(S,T) = \sum_{u \in S, v \in T} c(u,v) . \]

Here, we only sum over pairs $(u,v) \in E$ such that $u \in S, v \in T$. Meanwhile, given a flow $f$, the flow across an $s-t$ cut $(S,T)$ is the total net flow from $S$ to $T$, which is

\[ F(S,T) = \sum_{u \in S, v \in T} (f(u,v) - f(v,u)) . \]

The Min $s-t$ Cut problem is, given an input graph to max flow, to find the $s-t$ cut that minimizes $K(S,T)$. This will turn out to be highly related to the max flow problem.

Exercise 6.

Consider the following input graph and flow. Let $S = \{s,w,x\}$ and $T = \{v,t\}$. What is $K(S,T)$? What is $F(S,T)$? And what is the minimum $s-t$ cut in the graph and what is its capacity?

Label 4/4 on (s,v). Label 0/9 on (s,w). Label 0/7 on (w,v). Label 2/2 on (v,t). Label 2/5 on (v,x). Label 0/3 on (w,x). Label 2/9 on (x,t).
Solution.

$K(S,T) = 4 + 7 + 9 = 20$.

$F(S,T) = 4 + 0 - 2 + 2 = 4$.

The min cut is $S = \{s,w,v\}, T = \{x,t\}$ and its value is $2 + 5 + 3 = 10$.


It turns out that the flow across the cut is the same for any $s-t$ cut we choose! It's just the amount of flow.

Lemma 1.

Let $f$ be a flow. Then for any $s-t$ cut $(S,T)$, we have $F(S,T) = |f|$.


Proof.

Let us start with the cut $S = V \setminus \{t\}, T = \{t\}$. Here we have $F(S,T) = |f|$ by definition of the amount of flow: the net amount of flow into $t$. Now let us consider any $u \in V, u \neq s, u \neq t$. We will move $u$ from the "S" part of the cut to the "T" part. But we claim $F(S,T)$ has not changed: the amount we've added is $\sum_{v \in S} \left(f(v,u) - f(u,v)\right)$ and the amount we've subtracted is $\sum_{v \in T} \left(f(u,v) - f(v,u)\right)$. By the net flow constraint, these add up to zero.

Now we repeat with any other vertex, and so on, and we can create any $s-t$ cut without changing the amount of flow across the cut.


But we also know that flow across the cut is upper-bounded by the capacity of the cut.

Lemma 2.

Let $f$ be a valid flow and $(S,T)$ an $s-t$ cut. Then $F(S,T) \leq K(S,T)$.


Proof.

We have $F(S,T) = \sum_{u \in S, v \in T} f(u,v) - f(v,u) \leq \sum_{u,v} f(u,v) \leq \sum_{u,v} c(u,v) = K(S,T)$.


Now we can prove that Ford-Fulkerson is correct.

Theorem 1.

Let $f$ be a valid flow and $G_f$ the residual graph. Then $f$ is a max flow if and only if there is no path from $s$ to $t$ in $G_f$. Furthermore, in this case, the following cut is a min $s$-$t$ cut: $S = $ the set of vertices reachable from $s$, and $T = V \setminus S$.


Proof.

If there is a path in $G_f$, then we can augment the flow along this path, so $f$ could not be a max flow. On the other hand, suppose there is no path. Let $S,T$ be defined as in the lemma statement. Then for every edge $(u,v)$ with $u \in S, v \in T$, we have $f(u,v) = c(u,v)$, as otherwise $(u,v)$ would be an edge in $G_f$. And we have $f(v,u) = 0$ for the same reason. So $F(S,T) = K(S,T)$.

But we know that, for all possible $s-t$ cuts $(S',T')$, we have $K(S,T) = F(S,T) = F(S',T') \leq K(S',T')$. This proves that $(S,T)$ is a min cut. So we know that, for any flow $f'$, we have $|f'| \leq K(S,T) = F(S,T) = |f|$. This proves that $f$ is a max flow.


Corollary 1.

For any algorithm following the Ford-Fulkerson framework, if it halts, then it is correct.


This corollary follows because FF only halts if there is no path from $s$ to $t$ in the residual graph.

Corollary 2 (Max-Flow Min-Cut Theorem).

In any graph, the max $s-t$ flow is equal to the min $s-t$ cut.


The corollary follows because Ford-Fulkerson, assuming it halts, finds a max flow that equals a min cut, every time.

Using Ford-Fulkerson to find a min cut

Knowing what we now know, finding a min cut in a graph is straightforward:

  1. Use a Ford-Fulkerson algorithm to find a maximum flow $f$.
  2. Let $G_f$ be the residual graph.
  3. Let $S = $ the set of vertices reachable from $s$ in $G_f$; we can use e.g. BFS to find this set. Let $T = V \setminus S$.
  4. Return $(S,T)$.

To recap, we know that $(S,T)$ is a min cut because for every edge from $S$ to $T$, the flow equals the capacity, and there are no reverse edges with flow (otherwise $T$ would be reachable), so $F(S,T) = K(S,T)$.

Exercise 7.

Here is a graph with a flow. Actually, this flow is already a max flow. Run an iteration of Ford Fulkerson starting from here, draw the residual flow, and use it to find a min cut.

Label 4/4 on (s,v). Label 6/9 on (s,w). Label 3/7 on (w,v). Label 2/2 on (v,t). Label 5/5 on (v,x). Label 3/3 on (w,x). Label 8/9 on (x,t).
Solution.

Residual flow:

0 on (s,v), 4 on (v,s). 3 on (s,w), 6 on (w,s). 4 on (w,v), 3 on (v,w). 0 on (v,t), 2 on (t,v). 0 on (v,x), 5 on (x,v). 0 on (w,x), 3 on (x,w). 1 on (x,t), 8 on (t,x).

We have $S = \{s,v,w\}$ and $T = \{x,t\}$. The value of the min cut is 10.




Section 4: Implementing Ford-Fulkerson and Running Time

This section discusses an implementation of Ford-Fulkerson called Edmonds-Karp and analyzes its running time.

Objectives. After learning this material, you should be able to:

Using Breadth-First Search

The part of Ford-Fulkerson that is not fully specified is how to choose a path from $s$ to $t$ in the residual graph, $G_f$. We will simply use BFS. The resulting algorithm is called Edmonds-Karp.


// Algorithm 1: Edmonds-Karp
1  edmondskarp(G, c):
2      // G is a directed graph, c is a capacity function
3      let f(u,v) = 0 for all vertex pairs u,v
4      repeat:
5          let Gf and rf = residuals(G, c, f)
6          "color: purple;">use BFS to find a path from s to t in Gf
7          let f and d = augment(G, f, rf, path)
8          if d == 0:
9              return f

Because Edmonds-Karp is in the Ford-Fulkerson framework, we know that it is correct as long as it halts. We will show that it halts and give a bound on the number of time steps. The proof is "bonus material".

Proposition 1.

On a graph with $n$ vertices and $m$ edges, Edmonds-Karp runs in time $O(n m^2)$.


Proof (optional).

In a round of Edmonds-Karp, an edge is called critical if we augment along a path containing that edge, and the residual capacity is equal to the augmentation amount. In other words, that edge has the minimum residual capacity of any edge along the path.

Note that a critical edge is present in $G_f$ in the current round, but disappears in the next round, because the edge's capacity is fully saturated.

First, we show that in each round, a vertex's distance from $s$ in the residual graph $G_f$ can only increase. (This is the unweighted distance, i.e. number of hops.) To see this, consider the change in the residual graph. When we augment along a path $s=v_1,\dots,v_k=t$, we may add new reverse edges of the form $(v_j, v_{j-1})$ to $G_f$, and we remove forward edges if they are critical edges. Because $v_1,\dots,v_k$ is a shortest path from $s$, adding reverse edges cannot make any paths shorter, since we would never go through $v_{j+1}$ to get to $v_j$. And eliminating edges cannot make any paths shorter.

Next, we show that each edge $(u,v)$ can only be critical in at most $n/2$ iterations. When an edge is critical, it is removed from the residual graph by augmenting. To become critical again, it must be added back into the flow graph by augmenting along the reverse direction, $(v,u)$. But that implies the distance from $s$ to $u$ has increased by at least $2$, since it was strictly less than the distance to $v$, and now it's strictly more, and the distance to $v$ has not decreased. Since the distance begins at zero or more, and ends at $n$ or less, and increases by at least $2$ each round, the total number of times the edge is critical is at most $n/2$.

Finally, we put the pieces together. There are up to $2m$ potential edges in the residual graph: each edge in the original graph, and its reverse. Each can be critical at most $n/2$ times, and every round there is at least one critical edge, so there are at most $(2m)(n/2) = mn$ iterations. In each iteration, we do a constant amount of work and run BFS, which takes $O(m + n)$ time. We can assume that $m \geq n-1$ here, as the graph can be assumed to be connected, so the running time of BFS is $O(m)$. Putting it all together, we have a running time of $O((mn)(m)) = O(n m^2)$.



Section 5: Reductions and Applications

This section discusses how we can solve other problems by turning them into max-flow problems.

Objectives. After learning this material, you should be able to:

Variants of max flow

First, we will look at other versions of the max flow problem. It would be nice if we didn't have to come up with a new algorithm every time we changed the problem slightly! As we will see, often we can solve a slightly different problem by "reducing" it to max flow.

Antiparallel edges

A pair of antiparallel edges are $(u,v)$ and $(v,u)$, i.e. two directed edges between two vertices pointing opposite directions. Remember that we solved max flow assuming that the input graph contains no antiparallel edges. Actually, one can modify our solution to account for antiparallel edges, but here is a method using a reduction.

Here's how we construct $G_2$ and $c_2$.



Left: an edge in the original graph, $G_1$. Right: the result in $G_2$ after the reduction.

Now, we need to explain how to convert $f_2$ into $f_1$.

Proposition 2.

The above reduction is correct, i.e. $f_1$ is a maximum valid flow for $G_1, c_1$.


Proof.

First, we need to prove that $G_2$ has no antiparallel edges. That will tell us that $f_2$ is a correct output for $G_2, c_2$. Then, we need to prove that, since $f_2$ is correct, $f_1$ is correct.

To show $G_2$ has no antiparallel edges, notice that every edge in $G_2$ is either of the form $(u, w_{u,v})$ or $(w_{u,v}, v)$. In either case, there is no antiparallel edge. For example, if originally there was an antiparallel edge $(v,u)$, then there will be an edge $(v, w_{v,u})$, but $w_{v,u}$ is a different vertex than $w_{u,v}$.

Now, we know $f_2$ is a max flow for $G_2, c_2$. Notice that the total amount of flow satisfies $|f_2| = |f_1|$. So we just need to show that the min $s-t$ cut the graphs are equal. This will imply that $f_1$ is a max flow for $G_1, c_1$. (Actually, we are using the fact that the max-flow min-cut theorem applies for graphs with antiparallel edges, but this turns out to be true.)

Let $S_1,T_1$ be an $s-t$ cut in $G_1, c_1$. The capacity of the cut is $K(S_1,T_1) = \sum_{u \in S_1,v \in T_1} c(u,v)$. Now consider the following cut in $G_2, c_2$: We first let $S_2 = S_1, T_2 = T_1.$ Then, we add all vertices of the form $w_{u,v}$ to the same element as $u$. Now, we claim that $K(S_2,T_2) = K(S_1,T_1)$. This follows because the only edges crossing the cut are of the form $(w_{u,v}, v)$ and they cross the cut if and only if $(u,v)$ crosses the cut $S_1,T_1$ in the original graph. And they have the same capacity, i.e. $c_2(w_{u,v},v) = c_1(u,v)$.


Multiple sources and sinks

Suppose we have a max flow problem, but there are multiple possible sources of flow and multiple possible sinks. The new goal is to maximize the total flow into all of the sinks. The constraints on a flow are the same, except that now the net flow constraint does not apply to any of the sources or sinks.

Exercise 8.

Give a reduction from max flow with multiple sources and sinks to max flow. Sketch a proof of correctness.

Example solution.

First we give the reduction. As before, we need two parts:

  1. Given an instance $G_1,c_1$ of the problem of max flow with multiple sources and sinks, construct an instance $G_2,c_2$ of max flow.
  2. Given the solution $f_2$ to max flow, construct the solution $f_1$ to max flow with multiple sources and sinks.

For 1, Let $G_1,c_1$ be the original graph. We construct a new graph $G_2$ by taking a copy of $G_1$ and adding a "supersource" $s^*$ and "supersink" $t^*$. For each source $s$ in $G_1$, we add an edge $(s^*, s)$ with capacity infinity. (Actually, we can just set the capacity to any large enough number, e.g. the sum of all the capacities of the original graph.) For each sink $t$ in $G_1$, we add an edge $(t, t^*)$ with capacity infinity as well.

For 2, given $f_2$, we simply remove $s^*,t^*$ and all of their edges, and this gives us $f_1$.

Now that we have the reduction, we sketch a proof of correctness. $G_2,c_2$ is a valid instance of max flow, since it has only one source and one sink. Informally, the reduction works because we allowed it to send as much flow out of each source $s$ and as much flow into each sink $t$ as possible, while otherwise respecting all the constraints of a flow. More formally, we again need to know that the max-flow min-cut theorem applies with multiple sources and sinks, which it does (where the cut must have all sources in $S$ and all sinks in $T$). In this case, we can see that a min cut of $G_2,c_2$ would never contain any of the "infinity" edges, so a min cut in $G_2,c_2$ is the same as in $G_1,c_1$. Since the flow amounts are the same as well, this proves that $f_1$ is optimal in $G_1,c_1$.