Блог пользователя Tanzir5

Автор Tanzir5, история, 9 лет назад, По-английски

I've been trying to understand Dinic's Max Flow algorithm. I think I've fairly understood how the algorithm works.

In each iteration, you create a level graph using BFS and then find blocking flow in that level graph. You would need O(N) iterations and in each iteration, blocking flow can be found in O(NM) complexity. This is the place where I'm stuck. I've seen some implementations like Stanford Notebook Dinic implementation . But it seems to me that in the worst case you might need O(M^2) complexity to find the blocking flow if you implement the code this way. Can anyone help me to understand why the complexity is O(NM) for finding blocking flow ?

  • Проголосовать: нравится
  • +25
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Hello random people downvoting a valid question. Care to explain ?

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

First you run bfs which is O(M)

Then you run dfs which would run in O(M) but sometimes you return to the origin (when you find path to the end). Suppose between to returns to origin you visited X edges and found path from s to t is Y. It means that you spent X time, and will never run through other X - Y edges (Note that to really skip them there's array of pt in the code)

So, overall time will be = But is O(NM) because each Y does not exceed N and you do at most O(M) such sub-iterations, because each time you do it, you fill an edge completely.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

A little bit off topic. I found this code in which it is said that it runs in O(N * M * log(MC)), where MC is maximum edge capacity. Can someone explain why such a complexity?