ISAP peor momento complejidad de O (n * n * m) y Dinic están aumentando algoritmo del camino, pero BFS ISAP sólo una vez, así que básicamente mucho más rápido que Dinic.
código
#include <iostream> #include < string > #include <cstdio> #include <algoritmo> #include <cstring> #include <math> #include <cola> #include <funcional> #include <mapa> #include < conjunto > #include <pila> #define FT (a, b) memset (a, b, sizeof (a)) #define FAT (a) memset (a, 0, sizeof (a)) usando espacio de nombres std; typedef largo largo ll; 10 ; const int N = 2E4 + 10 ; const int INF = 0x3f3f3f3f ; const int mod = 1e9 + 7 ; int n, m, s, t; int h [N], e [M], ne [M], w [M], idx; int Deepth [N], brecha [N]; void add ( int a, int b, int c) { e [idx] = b, ne [idx] = h [a], w [idx] = c, h [a] = idx ++ ; } Void BFS () { FT (Deepth, - 1 ); FAT (brecha); cola< Int > q; q.push (t); Deepth [t] = 0 ; brecha [ 0 ] = 1 ; mientras que (q.size ()) { int a = q.front (); q.pop (); para ( int i = h [a]; ~ i; i = ne [i]) { int j = e [i]; si (Deepth [j] == - 1 ) { Deepth [j] = Deepth [a] + 1 ; brecha [Deepth [j]] ++ ; q.push (j); } } } } // int ans; int dfs ( int ahora, int flujo) { si (ahora == t) { // ans + = fluir; volver de flujo; } Int nowflow = 0 ; para ( int i = h [ahora]; ~ i; i = ne [i]) { int j = e [i]; si (w [i] && Deepth [j] + 1 == Deepth [ahora]) { int = k dfs (j, min (flujo - nowflow, w [i])); w [i] - = k, w [i ^ 1 ] + = k, nowflow + = k; si (nowflow == flujo) de regreso nowflow; } } - brecha [Deepth [ahora]]; si (! brecha [Deepth [ahora]]) brecha [s] = n + 2 ; ++ Deepth [ahora]; ++ gap [Deepth [ahora]]; volver nowflow; } Int ISAP () { int ans = 0 ; BFS (); mientras(GAP [s] < n) ans + = DFS (s, inf); volver ans; } Int main () { #ifdef ONLINE_JUDGE #else freopen ( " D: //code//c++//in.txt " , " r " , la entrada estándar); #endif scanf ( " % d% d% d% d " , y n, y m, y s, y t); FT (h, - 1 ); idx = 0 ; para ( int i = 0 ; i <m; i ++ ) { inta B C; scanf ( " % d% d% d " , & a, y b, y c); añadir (a, b, c), añadir (b, a, 0 ); } Printf ( " % d \ n " , ISAP ()); volver 0 ; }