Skip to content

Commit

Permalink
fix #51: add assert for mcf_graph.add_edge
Browse files Browse the repository at this point in the history
  • Loading branch information
yosupo06 committed Sep 22, 2020
1 parent 7feec57 commit 090a939
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions atcoder/mincostflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ template <class Cap, class Cost> struct mcf_graph {
int add_edge(int from, int to, Cap cap, Cost cost) {
assert(0 <= from && from < _n);
assert(0 <= to && to < _n);
assert(0 <= cap);
assert(0 <= cost);
int m = int(pos.size());
pos.push_back({from, int(g[from].size())});
int from_id = int(g[from].size());
Expand Down
9 changes: 8 additions & 1 deletion test/unittest/mincostflow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@ TEST(MincostflowTest, SameCostPaths) {
ASSERT_EQ(2, g.add_edge(0, 2, 2, 1));
auto expected = std::vector<std::pair<int, int>>{{0, 0}, {3, 3}};
ASSERT_EQ(expected, g.slope(0, 2));
}
}

TEST(MincostflowTest, Invalid) {
mcf_graph<int, int> g(2);
// https://github.com/atcoder/ac-library/issues/51
EXPECT_DEATH(g.add_edge(0, 0, -1, 0), ".*");
EXPECT_DEATH(g.add_edge(0, 0, 0, -1), ".*");
}

0 comments on commit 090a939

Please sign in to comment.