Skip to content

Commit dd53a96

Browse files
authored
Merge pull request #52 from atcoder/patch/issue51
fix #51: add assert for mcf_graph.add_edge
2 parents 7feec57 + 090a939 commit dd53a96

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: atcoder/mincostflow.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ template <class Cap, class Cost> struct mcf_graph {
1717
int add_edge(int from, int to, Cap cap, Cost cost) {
1818
assert(0 <= from && from < _n);
1919
assert(0 <= to && to < _n);
20+
assert(0 <= cap);
21+
assert(0 <= cost);
2022
int m = int(pos.size());
2123
pos.push_back({from, int(g[from].size())});
2224
int from_id = int(g[from].size());

Diff for: test/unittest/mincostflow_test.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@ TEST(MincostflowTest, SameCostPaths) {
8787
ASSERT_EQ(2, g.add_edge(0, 2, 2, 1));
8888
auto expected = std::vector<std::pair<int, int>>{{0, 0}, {3, 3}};
8989
ASSERT_EQ(expected, g.slope(0, 2));
90-
}
90+
}
91+
92+
TEST(MincostflowTest, Invalid) {
93+
mcf_graph<int, int> g(2);
94+
// https://github.com/atcoder/ac-library/issues/51
95+
EXPECT_DEATH(g.add_edge(0, 0, -1, 0), ".*");
96+
EXPECT_DEATH(g.add_edge(0, 0, 0, -1), ".*");
97+
}

0 commit comments

Comments
 (0)