File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 33 * Date: 2019-04-26
44 * License: CC0
55 * Source: https://cp-algorithms.com/graph/dinic.html
6- * Description: Flow algorithm with guaranteed complexity $O(V^2E) $.
7- * $O(\sqrt{V}E)$ for bipartite graphs, $O(\ min(V ^{1/2}, E ^{2/3})E))$ for unit graphs .
6+ * Description: Flow algorithm with complexity $O(VE\log U)$ where $U = \max |\text{cap}| $.
7+ * $O(\min(E ^{1/2}, V ^{2/3})E)$ if $U = 1$; $O(\sqrt{V}E )$ for bipartite matching .
88 * To obtain the actual flow, look at positive values only.
99 * Status: Tested on SPOJ FASTFLOW and SPOJ MATCHING
1010 */
@@ -34,13 +34,13 @@ struct Dinic {
3434 }
3535 ll calc (int s , int t ) {
3636 ll flow = 0 ; q [0 ] = s ;
37- do {
37+ rep ( L , 0 , 31 ) do { // 'int L=30' maybe faster for random data
3838 lvl = ptr = vi (sz (q ));
3939 int qi = 0 , qe = lvl [s ] = 1 ;
4040 while (qi < qe && !lvl [t ]) {
4141 int v = q [qi ++ ];
4242 trav (e , adj [v ])
43- if (!lvl [e .to ] && e . f < e .c )
43+ if (!lvl [e .to ] && ( e . c - e .f ) >> ( 30 - L ) )
4444 q [qe ++ ] = e .to , lvl [e .to ] = lvl [v ] + 1 ;
4545 }
4646 while (ll p = dfs (s , t , LLONG_MAX )) flow += p ;
You can’t perform that action at this time.
0 commit comments