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

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

Hello everyone.

A few months ago, I read the proof for the complexity of Edmonds-Karp algorithm O(VE2) in "Introduction to Algorithms" and Dinic's algorithm O(V2E) on Maximal. Both proofs are convincing in the sense that they provide a correct upper bound. Also, the output-sensitive complexity O(flow·E) helps in some problems.

However, due to the graph constraints, some problems I encounter make me feel reluctant to:

  1. consider running a max flow algorithm as a subroutine, so I try to come up with another idea.
  2. select the algorithm that will pass the time limit (coding time vs. running time).

Here is an example of such problems: ASC 4 — A. Unique Attack. With the given graph constraints (1 ≤ V ≤ 800, 1 ≤ E ≤ 10000), it seems that max flow algorithms will not pass in 1 second. However, they do! (even Edmonds-Karp).

I was wondering if someone can provide a (quite large generated) test case that is close to the upper bound or maybe share intuitions/approximations/estimates for a tighter bound.

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

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

Dinic with scaling works in where is the maxflow. And it's also very easy to write.

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

But still, can someone please provide a "worst-case" for MaxFlow? I have no idea how to go about constructing one of these.

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

I was always under impression it's not easy.

There is this paper I found: http://rain.ifmo.ru/~buzdalov/papers/cec15-flows.pdf

There is even some code on github so you can try to generate testcases yourself: https://github.com/mbuzdalov/papers/tree/master/2015-cec-flows

So yeah, this seems like relatively elaborate method. I played with it some time ago, and the cases are not that close to upper bound as you would like. (I didn't try particularly hard though.)

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

Why to learn MaxFlow when you have a president like me!!!

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

We often regard the complexity of max flow as O(be able to pass within the time limit) in China. The only thing we know is that it runs a lot faster than its theoretical complexity. And here is an example: V=10^6,E=4*10^6 and you're asked to get the max flow within 5 seconds. Link to the problem (in Chinese)

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

Complexity? No idea lol. My approach to flow problems is "write Ford-Fulkerson, hope it passes".

There are different implementations which can produce different runtime speeds, though. For example, you can push a flow in Ford-Fulkerson using BFS or DFS, but DFS (stopped when a flow is found) is usually faster and can give you some bullshit performance (flow++ in const. time) if the tests aren't very strong. When edges have non-unit capacity, you can push the maximum possible flow instead of just +1 at once, which can also help. Finally, randomisation of the DFS can help a lot against those tests where a usual implementation fails.

»
6 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +76 Проголосовать: не нравится

Today in Round 659 F the tests were week and I uphacked a solution. TBH I was surprised that this counter test was not well known, so I'll share the idea of it so that future problem setters would be aware of this.

It's simple: just span chains of length 1,2,...,sqrt(M) between the source and the sink. In this way, Dinic takes $$$O(M \sqrt{M})$$$ time, which is the worst complexity when all capacities are unit. Besides, we can make even stronger tests by using capacities larger than $$$1$$$. See this implementation for more details.

BTW, when the limit of capacities is a small value $$$V$$$, the complexity of the Dinic is clearly bounded by $$$O(VM \sqrt{VM})$$$, but I don't know if it is possible to achieve that upper bound. Is there anyone who knows about this?