Search code examples
javaalgorithmpseudocodeedmonds-karp

How to get the cut-set using the Edmonds–Karp algorithm?


I implemented the Edmonds–Karp algorithm using the Pseudocode that I found in the Edmonds–Karp algorithm wiki page: http://en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm

It works great, yet the algorithm output is the max flow value(min cut value), I need to the list of edges that this cut contains

I tried to change the algorithm, with no success, can you guys help?

Thank you


Solution

  • If you already have the flow, then compute the residual graph. Then do a depth first search from the source (or breadth first search, I don't think it matters), to compute the vertices in one half of the cut (S). The remaining vertices are in the other half of your cut, T.

    This gives you your cut (S, T). If you specifically want the edges between S and T, you could iterate through all the edges, selecting the ones which connect S and T. (Though there may a be a more eleegant way to do this last part.)