@@ -162,8 +162,7 @@ pub fn MfGraph(comptime Cap: type) type {
162162 }
163163
164164 /// Overwrite the capacity/flow of the `i`-th edge.
165- /// Changes the capacity and the flow amount of the `i`-th edge to
166- /// `new_cap` and `new_flow`, respectively.
165+ /// Changes the capacity and the flow amount of the `i`-th edge to `new_cap` and `new_flow`, respectively.
167166 /// It doesn't change the capacity or the flow amount of other edges.
168167 ///
169168 /// # Constraints
@@ -189,13 +188,66 @@ pub fn MfGraph(comptime Cap: type) type {
189188 }
190189
191190 /// Augments the flow from `s` to `t` as much as possible.
192- /// It returns the amount of the flow augmented.
191+ /// Returns the amount of the flow augmented.
192+ ///
193+ /// It changes the flow amount of each edge.
194+ /// Let $f_e$ and $f_e'$ be the flow amount of edge $e$ before and after calling it, respectively.
195+ /// Precisely, it changes the flow amount as follows.
196+ ///
197+ /// - $0 \leq f_e' \leq c_e$
198+ /// - $g(v, f) = g(v, f')$ holds for all vertices $v$ other than $s$ and $t$.
199+ /// - $g(t, f') - g(t, f)$ is maximized under these conditions. It returns this $g(t, f') - g(t, f)$.
200+ ///
201+ /// # Constraints
202+ ///
203+ /// - $s \neq t$
204+ /// - $0 \leq s, t \lt n$
205+ /// - The answer should be in `Cap`.
206+ ///
207+ /// # Panics
208+ ///
209+ /// Panics if the above constraint is not satisfied.
210+ ///
211+ /// # Complexity
212+ ///
213+ /// - $O((n + m) \sqrt{m})$ (if all the capacities are $1$),
214+ /// - $O(n^2 m)$ (general), or
215+ /// - $O(F(n + m))$, where $F$ is the returned value
216+ ///
217+ /// where $m$ is the number of added edges.
193218 pub fn flow (self : * Self , s : usize , t : usize ) Allocator.Error ! Cap {
194219 return self .flowWithCapacity (s , t , std .math .maxInt (Cap ));
195220 }
196221
197222 /// Auguments the flow from `s` to `t` as much as possible, until reaching the amount of `flow_limit`.
198- /// It returns the amount of the flow augmented.
223+ /// Returns the amount of the flow augmented.
224+ ///
225+ /// It changes the flow amount of each edge.
226+ /// Let $f_e$ and $f_e'$ be the flow amount of edge $e$ before and after calling it, respectively.
227+ /// Precisely, it changes the flow amount as follows.
228+ ///
229+ /// - $0 \leq f_e' \leq c_e$
230+ /// - $g(v, f) = g(v, f')$ holds for all vertices $v$ other than $s$ and $t$.
231+ /// - $g(t, f') - g(t, f) \leq$ `flow_limit`
232+ /// - $g(t, f') - g(t, f)$ is maximized under these conditions. It returns this $g(t, f') - g(t, f)$.
233+ ///
234+ /// # Constraints
235+ ///
236+ /// - $s \neq t$
237+ /// - $0 \leq s, t \lt n$
238+ /// - The answer should be in `Cap`.
239+ ///
240+ /// # Panics
241+ ///
242+ /// Panics if the above constraint is not satisfied.
243+ ///
244+ /// # Complexity
245+ ///
246+ /// - $O((n + m) \sqrt{m})$ (if all the capacities are $1$),
247+ /// - $O(n^2 m)$ (general), or
248+ /// - $O(F(n + m))$, where $F$ is the returned value
249+ ///
250+ /// where $m$ is the number of added edges.
199251 pub fn flowWithCapacity (self : * Self , s : usize , t : usize , flow_limit : Cap ) Allocator.Error ! Cap {
200252 const n = self .n ;
201253 assert (s < n );
@@ -291,6 +343,17 @@ pub fn MfGraph(comptime Cap: type) type {
291343 return result ;
292344 }
293345
346+ /// Returns a boolean slice of length `n`, such that the `i`-th element is `true`
347+ /// if and only if there is a directed path from `s` to `i` in the residual network.
348+ /// The returned slice corresponds to a s-t minimum cut after calling `flow(s, t)` exactly once.
349+ ///
350+ /// The residual network is the graph whose edge set is given by gathering $(u, v)$
351+ /// for each edge $e = (u, v, f_e, c_e)$ with $f_e < c_e$ and $(v, u)$ for each edge $e$ with $0 < f_e$.
352+ /// Returns the set of the vertices that is reachable from `s` in the residual network.
353+ ///
354+ /// # Complexity
355+ ///
356+ /// - $O(n + m)$, where $m$ is the number of added edges.
294357 pub fn minCut (self : Self , s : usize ) Allocator.Error ! []bool {
295358 var visited = try self .allocator .alloc (bool , self .n );
296359 @memset (visited , false );
0 commit comments