8888 let mut prev_e = vec ! [ 0 ; n] ;
8989 let mut flow = T :: zero ( ) ;
9090 let mut cost = T :: zero ( ) ;
91- let mut prev_cost : Option < T > = None ;
91+ let mut prev_cost_per_flow : Option < T > = None ;
9292 let mut result = vec ! [ ( flow, cost) ] ;
9393 while flow < flow_limit {
9494 if !self . refine_dual ( source, sink, & mut dual, & mut prev_v, & mut prev_e) {
@@ -113,11 +113,11 @@ where
113113 let d = -dual[ source] ;
114114 flow += c;
115115 cost += d * c;
116- if prev_cost == Some ( d) {
116+ if prev_cost_per_flow == Some ( d) {
117117 assert ! ( result. pop( ) . is_some( ) ) ;
118118 }
119119 result. push ( ( flow, cost) ) ;
120- prev_cost = Some ( cost ) ;
120+ prev_cost_per_flow = Some ( d ) ;
121121 }
122122 result
123123 }
@@ -198,4 +198,15 @@ mod tests {
198198 assert_eq ! ( flow, 2 ) ;
199199 assert_eq ! ( cost, 6 ) ;
200200 }
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+ }
201212}
0 commit comments