6

Given undirected graph, all edges have weight 1; N, M are about 10^6 I need to find whether the flow between source and sink is bigger than some value X. X is quite small.

Using bfs until the flow is equal to X gives O(M*X) this is too slow for me.

Is there any quicker method to estimate flow?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Herokiller
  • 2,891
  • 5
  • 32
  • 50
  • Using BFS does not always give correct result. See counterexample in [Shortest two disjoint paths between two specified vertices](http://stackoverflow.com/q/11880738/1009831). – Evgeny Kluev Sep 04 '12 at 12:17
  • I mean Edmonds-Karp using bfs. – Herokiller Sep 04 '12 at 12:22
  • Wikipedia suggests that Karger's algorithm can find minimum cuts efficiently, would that do? – Nabb Sep 04 '12 at 13:20
  • don't understand how Karger's algorithm can help here – Herokiller Sep 04 '12 at 14:03
  • @Herokiller, it gives you an upper bound on the capacity each time it is run. When it bundles up a set of arcs, just replace them by one arc with the sum of the capacities. When one arc remains, you have a bound on the capacity. – vonbrand Feb 09 '13 at 02:52

1 Answers1

1

what you need is basically maxflow, see http://en.wikipedia.org/wiki/Maximum_flow_problem

and Dinic's algorithm is recommended for practical efficient.

and in case you need some example, you may refer to one of my code, at http://wiki.attiix.com/index.php?title=Maxflow

iloahz
  • 4,491
  • 8
  • 23
  • 31
  • as far as I understand Dinic's algorithm doesn't depend on the value of the flow, and O(VElogV) is too much – Herokiller Sep 05 '12 at 04:04
  • @Herokiller u a right, dinic doesn't concern the capacity of the edges, and i said it's practically efficient, O(VElogV) is the theoretic upper bound, which doesn't mean the actually run time, and dinic is every fast for leveled graphs, and for more general graphs, the only algo i know, which may be faster than dinic, is isap – iloahz Sep 05 '12 at 05:17