Skip to content

Commit aaaf8bc

Browse files
authored
Merge pull request #63 from atcoder/patch/maxflow
nit picking optimization for maxflow
2 parents 856c79d + b277628 commit aaaf8bc

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

atcoder/maxflow.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ template <class Cap> struct mf_graph {
9999
g[v][i].cap += d;
100100
g[e.to][e.rev].cap -= d;
101101
res += d;
102-
if (res == up) break;
102+
if (res == up) return res;
103103
}
104+
level[v] = _n;
104105
return res;
105106
};
106107

@@ -109,11 +110,9 @@ template <class Cap> struct mf_graph {
109110
bfs();
110111
if (level[t] == -1) break;
111112
std::fill(iter.begin(), iter.end(), 0);
112-
while (flow < flow_limit) {
113-
Cap f = dfs(dfs, t, flow_limit - flow);
114-
if (!f) break;
115-
flow += f;
116-
}
113+
Cap f = dfs(dfs, t, flow_limit - flow);
114+
if (!f) break;
115+
flow += f;
117116
}
118117
return flow;
119118
}

0 commit comments

Comments
 (0)