Skip to content

Commit

Permalink
Merge pull request #52 from atcoder/patch/issue51
Browse files Browse the repository at this point in the history
fix #51: add assert for mcf_graph.add_edge
  • Loading branch information
yosupo06 authored Sep 22, 2020
2 parents 7feec57 + 090a939 commit dd53a96
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 dd53a96

Please sign in to comment.