Skip to content

Instantly share code, notes, and snippets.

@akiradeveloper
Created January 19, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akiradeveloper/642f3fd66b748fa747d732d6690a816f to your computer and use it in GitHub Desktop.
Save akiradeveloper/642f3fd66b748fa747d732d6690a816f to your computer and use it in GitHub Desktop.
fn dfs(&mut self, v: usize, t: usize, f: u32) -> u32 {
if v == t { return f; }
self.used[v] = true;
for e in &mut self.g[v] {
if !self.used[e.to] && e.cap > 0 {
let d = self.dfs(e.to, t, std::cmp::min(f, e.cap)); // cannot borrow `*self` as mutable more than once at a time
if d > 0 {
e.cap -= d;
self.g[e.to][e.rev].cap += d; // cannot borrow `self.g` as mutable more than once at a time
return d;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment