Skip to content

Commit 2e85c7e

Browse files
committed
fix #5: maxflow is broken when s = t
1 parent 1084ef6 commit 2e85c7e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

atcoder/maxflow.hpp

+1
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;

test/unittest/maxflow_test.cpp

+7
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)