Skip to content

Commit

Permalink
Merge pull request #90 from MiSawa/fix/max-flow-return-condition
Browse files Browse the repository at this point in the history
Fix/max flow return condition
  • Loading branch information
qryxip authored Feb 23, 2021
2 parents 6593df1 + 463f0e2 commit 72fe2a1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/maxflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 72fe2a1

Please sign in to comment.