Skip to content

Max-flow #14

Open
Open
@pathikrit

Description

@pathikrit
int maxFlow(int[][] cap, int source, int sink) {
  for (int flow = 0; ; ++flow)
    if (!augmentPath(cap, new boolean[cap.length], source, sink))
      return flow;
}

boolean augmentPath(int[][] cap, boolean[] vis, int i, int sink) {
  if (i == sink) return true;
  vis[i] = true;
  for (int j = 0; j < vis.length; j++)
    if (!vis[j] && cap[i][j] > 0 && augmentPath(cap, vis, j, sink)) {
      --cap[i][j];
      ++cap[j][i];
      return true;
    }
  return false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions