88
88
let mut prev_e = vec ! [ 0 ; n] ;
89
89
let mut flow = T :: zero ( ) ;
90
90
let mut cost = T :: zero ( ) ;
91
- let mut prev_cost : Option < T > = None ;
91
+ let mut prev_cost_per_flow : Option < T > = None ;
92
92
let mut result = vec ! [ ( flow, cost) ] ;
93
93
while flow < flow_limit {
94
94
if !self . refine_dual ( source, sink, & mut dual, & mut prev_v, & mut prev_e) {
@@ -113,11 +113,11 @@ where
113
113
let d = -dual[ source] ;
114
114
flow += c;
115
115
cost += d * c;
116
- if prev_cost == Some ( d) {
116
+ if prev_cost_per_flow == Some ( d) {
117
117
assert ! ( result. pop( ) . is_some( ) ) ;
118
118
}
119
119
result. push ( ( flow, cost) ) ;
120
- prev_cost = Some ( cost ) ;
120
+ prev_cost_per_flow = Some ( d ) ;
121
121
}
122
122
result
123
123
}
@@ -198,4 +198,15 @@ mod tests {
198
198
assert_eq ! ( flow, 2 ) ;
199
199
assert_eq ! ( cost, 6 ) ;
200
200
}
201
+
202
+ #[ test]
203
+ fn same_cost_paths ( ) {
204
+ // https://github.com/atcoder/ac-library/blob/300e66a7d73efe27d02f38133239711148092030/test/unittest/mincostflow_test.cpp#L83-L90
205
+ let mut graph = MinCostFlowGraph :: new ( 3 ) ;
206
+ assert_eq ! ( 0 , graph. add_edge( 0 , 1 , 1 , 1 ) ) ;
207
+ assert_eq ! ( 1 , graph. add_edge( 1 , 2 , 1 , 0 ) ) ;
208
+ assert_eq ! ( 2 , graph. add_edge( 0 , 2 , 2 , 1 ) ) ;
209
+ let expected = [ ( 0 , 0 ) , ( 3 , 3 ) ] ;
210
+ assert_eq ! ( expected[ ..] , * graph. slope( 0 , 2 , i32 :: max_value( ) ) ) ;
211
+ }
201
212
}
0 commit comments