Skip to content

Commit 97e7c77

Browse files
authored
Merge pull request #38 from MiSawa/patch/issue37
fix #37: Fix deduplication by tangent
2 parents 839923f + c982204 commit 97e7c77

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

atcoder/mincostflow.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ template <class Cap, class Cost> struct mcf_graph {
122122
return true;
123123
};
124124
Cap flow = 0;
125-
Cost cost = 0, prev_cost = -1;
125+
Cost cost = 0, prev_cost_per_flow = -1;
126126
std::vector<std::pair<Cap, Cost>> result;
127127
result.push_back({flow, cost});
128128
while (flow < flow_limit) {
@@ -139,11 +139,11 @@ template <class Cap, class Cost> struct mcf_graph {
139139
Cost d = -dual[s];
140140
flow += c;
141141
cost += c * d;
142-
if (prev_cost == d) {
142+
if (prev_cost_per_flow == d) {
143143
result.pop_back();
144144
}
145145
result.push_back({flow, cost});
146-
prev_cost = cost;
146+
prev_cost_per_flow = d;
147147
}
148148
return result;
149149
}

test/unittest/mincostflow_test.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ TEST(MaxflowTest, SelfLoop) {
7979
mcf_graph<int, int>::edge e = {0, 0, 100, 0, 123};
8080
edge_eq(e, g.get_edge(0));
8181
}
82+
83+
TEST(MincostflowTest, SameCostPaths) {
84+
mcf_graph<int, int> g(3);
85+
ASSERT_EQ(0, g.add_edge(0, 1, 1, 1));
86+
ASSERT_EQ(1, g.add_edge(1, 2, 1, 0));
87+
ASSERT_EQ(2, g.add_edge(0, 2, 2, 1));
88+
auto expected = std::vector<std::pair<int, int>>{{0, 0}, {3, 3}};
89+
ASSERT_EQ(expected, g.slope(0, 2));
90+
}

0 commit comments

Comments
 (0)