Skip to content

Commit 51a9c98

Browse files
Added additional assertions and documentation
1 parent a793068 commit 51a9c98

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/maxflow.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)