From a595e8d0b73ffbf686055bc6719316dbdb804651 Mon Sep 17 00:00:00 2001 From: mi_sawa Date: Sun, 13 Sep 2020 16:21:17 +0900 Subject: [PATCH 1/2] fix #37: Fix deduplication by tangent --- 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 321f3e1..3bb7abd 100644 --- a/atcoder/mincostflow.hpp +++ b/atcoder/mincostflow.hpp @@ -143,7 +143,7 @@ template struct mcf_graph { result.pop_back(); } result.push_back({flow, cost}); - prev_cost = cost; + prev_cost = d; } return result; } diff --git a/test/unittest/mincostflow_test.cpp b/test/unittest/mincostflow_test.cpp index baec43f..cd8dcbd 100644 --- a/test/unittest/mincostflow_test.cpp +++ b/test/unittest/mincostflow_test.cpp @@ -79,3 +79,12 @@ TEST(MaxflowTest, SelfLoop) { mcf_graph::edge e = {0, 0, 100, 0, 123}; edge_eq(e, g.get_edge(0)); } + +TEST(MincostflowTest, SameCostPaths) { + mcf_graph g(3); + ASSERT_EQ(0, g.add_edge(0, 1, 1, 1)); + ASSERT_EQ(1, g.add_edge(1, 2, 1, 0)); + 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 From c9822044fcf42e7d4f35d5d10458194cb6ad0b84 Mon Sep 17 00:00:00 2001 From: mi_sawa Date: Sun, 13 Sep 2020 16:24:24 +0900 Subject: [PATCH 2/2] Rename a variable to avoid confusion --- atcoder/mincostflow.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atcoder/mincostflow.hpp b/atcoder/mincostflow.hpp index 3bb7abd..1db2f9e 100644 --- a/atcoder/mincostflow.hpp +++ b/atcoder/mincostflow.hpp @@ -122,7 +122,7 @@ template struct mcf_graph { return true; }; Cap flow = 0; - Cost cost = 0, prev_cost = -1; + Cost cost = 0, prev_cost_per_flow = -1; std::vector> result; result.push_back({flow, cost}); while (flow < flow_limit) { @@ -139,11 +139,11 @@ template struct mcf_graph { Cost d = -dual[s]; flow += c; cost += c * d; - if (prev_cost == d) { + if (prev_cost_per_flow == d) { result.pop_back(); } result.push_back({flow, cost}); - prev_cost = d; + prev_cost_per_flow = d; } return result; }