algorithm EdmondsKarp input: graph (graph[v] should be the list of edges coming out of vertex v. Each edge should have a capacity, flow, source and sink as parameters, as well as a pointer to the reverse edge.) s (Source vertex) t (Sink vertex) output: flow (Value of maximum flow) flow := 0 (Initialize flow to zero) repeat (Run a bfs to find the shortest s-t path. We use 'pred' to store the edge taken to get to each vertex, so we can recover the path afterwards) q := queue() q.push(s) pred := array(graph.length) while not empty(q) cur := q.poll() for Edge e in graph[cur] if pred[e.t] = null and e.t ≠ s and e.cap > e.flow pred[e.t] := e q.push(e.t) if not (pred[t] = null) (We found an augmenting path. See how much flow we can send) df := ∞ for (e := pred[t]; e ≠ null; e := pred[e.s]) df := min(df, e.cap - e.flow) (And update edges by that amount) for (e := pred[t]; e ≠ null; e := pred[e.s]) e.flow := e.flow + df e.rev.flow := e.rev.flow - df flow := flow + df until pred[t] = null (i.e., until no augmenting path was found) return flow