File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -118,13 +118,28 @@ where
118118 _re. cap = new_flow;
119119 }
120120
121+ /// `s != t` must hold, otherwise it panics.
121122 pub fn flow ( & mut self , s : usize , t : usize ) -> Cap {
122123 self . flow_with_capacity ( s, t, Cap :: max_value ( ) )
123124 }
125+ /// # Parameters
126+ /// * `s != t` must hold, otherwise it panics.
127+ /// * `flow_limit >= 0`
124128 pub fn flow_with_capacity ( & mut self , s : usize , t : usize , flow_limit : Cap ) -> Cap {
125129 let n_ = self . _n ;
126130 assert ! ( s < n_) ;
127131 assert ! ( t < n_) ;
132+ // By the definition of max flow in appendix.html, this function should return 0
133+ // when the same vertices are provided. On the other hand, it is reasonable to
134+ // return infinity-like value too, which is what the original implementation
135+ // (and this implementation without the following assertion) does.
136+ // Since either return value is confusing, we'd rather deny the parameters
137+ // of the two same vertices.
138+ // For more details, see https://github.com/rust-lang-ja/ac-library-rs/pull/24#discussion_r485343451
139+ // and https://github.com/atcoder/ac-library/issues/5 .
140+ assert_ne ! ( s, t) ;
141+ // Additional constraint
142+ assert ! ( Cap :: zero( ) <= flow_limit) ;
128143
129144 let mut calc = FlowCalculator {
130145 graph : self ,
You can’t perform that action at this time.
0 commit comments