Infoshoc's blog

By Infoshoc, history, 8 years ago, In English

Hello everyone! The question arose, while solving 100783D - Book Club. Somehow it was night when we read it, and first thought that got to my mind: in unit network with source, edges from source to all A's, edges from A to B and from B's to sink, flow should be equal to number of people. I started to search max flow algorithm which suits to limits and found out that Dinic used for solving bipartite problem takes O(sqrt(V)E) (Wow this is the case with E maximum N we can get O(N^1.5)). Ok I wrote Dinic almost like e-maxx it and it got as far as test 13 with TL.

Ok, said AndrewB330, why didn't you wrote Khun. I thought about it, and agreed that yes O(N^2) suits me. And got bloody AC.

The question is: what so horrible I did in Dinic or what should I have done so it worked as expected?

Thank you, community.

  • Vote: I like it
  • +10
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

http://ideone.com/Q0nevm
разница в строке 108

»
8 years ago, # |
Rev. 3   Vote: I like it +5 Vote: I do not like it

You should be doing DFS while augmenting is greater than 0, not only once per BFS.

PS: That's the mistake I was doing before which was preventing me from solving FASTFLOW on SPOJ so I knew what to look for :D