Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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), ".*");
}