[Knowledge] network flow board

#include <the iostream> 
#include <cstdio> 
#include <CString> 
#include <algorithm> 
#include <the cmath>
 the using  namespace STD;
 const  int N = 205 ;
 const  int INF = 2.14748 billion ;
 int n-, m, to [N * 2 ], NXT [N * 2 ], W [N * 2 ], head [N], CNT = . 1 , D [N], Q [N * . 4 ], ANS; // D: distance from point 1 to record path. 
void the Add ( int X, int Y, int V) 
{ 
  to [ ++ CNT] = Y; NXT [CNT] = head [X]; 
  W [CNT] = V; head [X] = CNT; 
} // 0. 1 = ^ 1,1 ^ 0,2 ^. 1 = 3,3 ^ 1 = 2 = 1, it is convenient to start numbering from the reverse side 2 
 // time from the start to build 2 reverse side, head do not move, its search connector edge, a second condition can be written as i. Convenient 
BOOL BFS () // determines whether there is passage, found some wide 
{ 
   Memset (D, 0 , the sizeof (D));
    int H = . 1 , T = . 1 ; 
   Q [ . 1 ] = . 1 ; 
   D [ . 1 ] = . 1 ;
    the while (H <= T) 
    { 
     int X = Q [H];
      for( Int I = head [X]; I; I = NXT [I])
      IF (! W [I] && D [to [I]]) // can not be walked stream and 
       { 
          D [to [I ]] = D [X] + . 1 ; 
          Q [ ++ T] = to [I]; 
       } 
       H ++ ; 
    } 
   IF (D [n-]) return  to true ;
    return  to false ; 
} 
int DFS ( int X, int V ) 
{ 
   IF (n-X || == V == 0 ) return V; // flow or no flow end of the 
   int F, RET = 0 ; // RET: all traffic for this search can find, f: present a search through the flow path may be 
   for ( int I = head [X]; I; I = NXT [I])
    IF (D [to [I]] == D [X] + . 1 ) // on that path found 
   { 
     F = DFS (to [I], min (W [I], V)); // can through-flow is equal to the search after allowing back flow through, and their minimum allowable flow. 
     W [I] - = F; // forward edge of the remaining traffic subtracting F 
     W [I ^ . 1 ] + = F; // reverse side remaining traffic plus f. Actually give him a chance to go back, self-adjusting. 
     F = V-; // may flow by subtracting the number of flies F 
     RET = F +; // total flow plus F 
     IF (V == 0 ) BREAK ;// not flow exit 
   } 
   return RET; 
} 
int main () 
{ 
   CIN >> m >> n-;
    for ( int I = . 1 ; I <= m; I ++ ) 
   { 
      int X, Y, V; 
      CIN >> the y->> >> the X- v; 
      the Add (the X-, the y-, v); // actually v here is the establishment of the article sides can now flow through much traffic.  
      the Add (Y, X, 0 );     // Edges in Reverse 
         }
    the while (BFS ()) + ANS DFS = ( . 1 , INF); // long as the left channel. Assuming he can stream unlimited, then slowly adjust 
   cout << ANS << endl;
 return  0;
}

Guess you like

Origin www.cnblogs.com/carrotmvp/p/12179516.html