Greedy flow counterexample [00S5]

Unfortunately, this greedy flow algorithm does not work. We may get stuck in a “local optimum” where there are no more unsaturated paths, but we have not found the globally maximum flow. Here is a counterexample.

Clearly, the value of a maximum flow in this network is 2 (send one unit of flow along the top and another unit along the bottom). However, if the algorithm happens to pick the path s \to a \to b \to t the first time through the loop, we end up with this:
and there are no longer any unsaturated paths from s \to t. The problem is that we shouldn’t have picked the middle edge, but there’s no way to know that ahead of time.

However, all is not lost! We can actually keep the basic outline of the greedy algorithm. We really just need to allow ourselves to undo or “push back” flow if we find somewhere better for it to go.