diff --git a/src/maxflow.rs b/src/maxflow.rs index 93b337c..507cd6e 100644 --- a/src/maxflow.rs +++ b/src/maxflow.rs @@ -201,7 +201,7 @@ where self.graph.g[e_to][e_rev].cap -= d; res += d; if res == up { - break; + return res; } } self.iter[v] = self.graph.g[v].len(); @@ -320,4 +320,15 @@ mod test { assert_eq!(graph.flow(s, t), 2); } + + #[test] + fn test_dont_repeat_same_phase() { + let n = 100_000; + let mut graph = MfGraph::new(3); + graph.add_edge(0, 1, n); + for _ in 0..n { + graph.add_edge(1, 2, 1); + } + assert_eq!(graph.flow(0, 2), n); + } }