xuanquang1999's blog

By xuanquang1999, history, 2 years ago, In English,

I'm trying to solve 720B — Cactusophobia from Russian Code Cup 2016 Final. I read the editorial and understood the flow solution for this problem. So I find some implementation for this problem. I read dreamoon's solution (20732895), which used Dinic flow finding algorithm and run in 373ms. But, since Dinic algorithm run in O(n2m), and the graph can have up to 30000 vertices and edges, how could this run in time? Can someone enlighten me about this? Thanks in advance.

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

»
2 years ago, # |
Rev. 2   Vote: I like it +29 Vote: I do not like it

Sum of capacity of all edges is O(n). You can imagine an edge with capacity x as x edges with capacity 1. It'll be a unit graph, hence Dinic's algorithm will run in .

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

Dinic is min(fE, V^2E), and f <= V, so it is O(VE). (As above comment mentioned, tighter bounds are possible)