Skip to content

Commit b9fbc16

Browse files
authored
Merge pull request #21 from atcoder/patch/issue5
fix #5: maxflow was broken when s = t
2 parents 364ea04 + 12fb855 commit b9fbc16

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

atcoder/maxflow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ template <class Cap> struct mf_graph {
6565
Cap flow(int s, int t, Cap flow_limit) {
6666
assert(0 <= s && s < _n);
6767
assert(0 <= t && t < _n);
68+
assert(s != t);
6869

6970
std::vector<int> level(_n), iter(_n);
7071
internal::simple_queue<int> que;

document_en/maxflow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ It adds an edge oriented from the vertex `from` to the vertex `to` with the capa
4848

4949
**@{keyword.constraints}**
5050

51+
- $s \neq t$
5152
- The answer should be in `Cap`.
5253

5354
**@{keyword.complexity}**

document_ja/maxflow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int graph.add_edge(int from, int to, Cap cap);
4949

5050
**@{keyword.constraints}**
5151

52+
- $s \neq t$
5253
- 帰り値が `Cap` に収まる
5354

5455
**@{keyword.complexity}**

test/unittest/maxflow_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,10 @@ TEST(MaxflowTest, SelfLoop) {
178178
mf_graph<int>::edge e = {0, 0, 100, 0};
179179
edge_eq(e, g.get_edge(0));
180180
}
181+
182+
TEST(MaxflowTest, Invalid) {
183+
mf_graph<int> g(2);
184+
// https://github.com/atcoder/ac-library/issues/5
185+
EXPECT_DEATH(g.flow(0, 0), ".*");
186+
EXPECT_DEATH(g.flow(0, 0, 0), ".*");
187+
}

0 commit comments

Comments
 (0)