From 090a9393e4b3076391bd73d183021d5bde3209e4 Mon Sep 17 00:00:00 2001 From: Kohei Morita Date: Tue, 22 Sep 2020 14:22:55 +0900 Subject: [PATCH] fix #51: add assert for mcf_graph.add_edge --- atcoder/mincostflow.hpp | 2 ++ test/unittest/mincostflow_test.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/atcoder/mincostflow.hpp b/atcoder/mincostflow.hpp index 1db2f9e..f7bfc9f 100644 --- a/atcoder/mincostflow.hpp +++ b/atcoder/mincostflow.hpp @@ -17,6 +17,8 @@ template 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()); diff --git a/test/unittest/mincostflow_test.cpp b/test/unittest/mincostflow_test.cpp index fdf027d..ea31e7c 100644 --- a/test/unittest/mincostflow_test.cpp +++ b/test/unittest/mincostflow_test.cpp @@ -87,4 +87,11 @@ TEST(MincostflowTest, SameCostPaths) { ASSERT_EQ(2, g.add_edge(0, 2, 2, 1)); auto expected = std::vector>{{0, 0}, {3, 3}}; ASSERT_EQ(expected, g.slope(0, 2)); -} \ No newline at end of file +} + +TEST(MincostflowTest, Invalid) { + mcf_graph 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), ".*"); +}