Skip to content

Commit 72fe2a1

Browse files
authored
Merge pull request #90 from MiSawa/fix/max-flow-return-condition
Fix/max flow return condition
2 parents 6593df1 + 463f0e2 commit 72fe2a1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/maxflow.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ where
201201
self.graph.g[e_to][e_rev].cap -= d;
202202
res += d;
203203
if res == up {
204-
break;
204+
return res;
205205
}
206206
}
207207
self.iter[v] = self.graph.g[v].len();
@@ -320,4 +320,15 @@ mod test {
320320

321321
assert_eq!(graph.flow(s, t), 2);
322322
}
323+
324+
#[test]
325+
fn test_dont_repeat_same_phase() {
326+
let n = 100_000;
327+
let mut graph = MfGraph::new(3);
328+
graph.add_edge(0, 1, n);
329+
for _ in 0..n {
330+
graph.add_edge(1, 2, 1);
331+
}
332+
assert_eq!(graph.flow(0, 2), n);
333+
}
323334
}

0 commit comments

Comments
 (0)