0

I was recently trying to solve a max flow problem on spoj. I saw an algorithm for max flow here, so I applied it but I was not getting the required answer. The reason was I decreased the capacity of edge towards sink in my implementation and eventually it reaches zero and it does not consider the reverse capacity (which many people claimed in online to add two edges one forward and one backward in place of one undirected edge). Could you please help me out from this or tell me how to solve problem using Edmonds-Karp algorithm.

mrBen
  • 276
  • 1
  • 5
  • 15
  • 2
    Edmond Karp is too slow for that problem try using Dinic or Push-Relabel – Photon Aug 31 '20 at 06:16
  • could you please tell me how in the problem given above has flow 5 i thought it is 3 as maximum capacity is 3 in the edge from 3 to 4 – dhathrish avs Aug 31 '20 at 10:44
  • It's written after sample statement... citing: `Viewing the problem as max-flow, we may send 3 units of flow through the path 1 - 2 - 3 - 4 and 2 units of flow through the path 1 - 3 - 4. Viewing the problem as min-cut, we may cut the first and third edges. Either way the total is 5.` – Photon Aug 31 '20 at 12:09
  • when we send the flow across 1-2-3-4 the capacity of 3-4 is reduced by 3 thus resulting in a capacity of 0 across 3-4 then how can we add flow of 2 again in 1-3-4 path.I am quite confused in this part.Could you please help me out – dhathrish avs Aug 31 '20 at 15:42
  • The problem is weird, as edges are undirected but edges 3-4 have capacity for both 3 4 and 4 3, so I guess they add up. At the end you have a capacity of 6 and 3-4 is not the limiting edge. – mrBen Aug 31 '20 at 15:59
  • if at all we consider they add up, then the max flow for the given graph should be 6 beacuse we should consider doubling up like that for every edge in the graph which results in a flow of 6(just considering path 1-2-3-4) but it's mentioned that the flow is 5. – dhathrish avs Aug 31 '20 at 16:37
  • The edge 3-1 as only a capacity of 2, so it is limiting in the path 1-3-4. At the end 1-2-3-4 have a capacity of 3 and 1-3-4 a capacity of 2, so 5 in total. – mrBen Sep 01 '20 at 09:23
  • i could't agree with you,you are considering path 1-3-4 with capacity 2 and 1-2-3-4 path with capacity 3 where as the capacity for 3-4 is 3 which is common in both,if at all we consider doubling up we should consider doubling up all edges and eventually we don't need 1-3-4 path in that case because 1-2-3-4 path has already a capacity of 6.Correct me if i am wrong somewhere – dhathrish avs Sep 02 '20 at 02:17
  • I said earlier that the problem was weird, I should have said the data are weird. Edges are undirected so it doesn't matter if capacity is for one direction or the other. But edge 3-4 appear both as 3 4 and as 4 3 (with capacity of 3 each time) and others edges appear only once. So I guess you need to add the two capacities for edge 3-4, but not for the others edges (as they only appear once). Doing so, you find the same result as expected. – mrBen Sep 02 '20 at 07:33

0 Answers0