Maximum Flow Review

The maximum flow is the most primitive of network flow, active and sink source is infinite

FF algorithm (idea was simply to find someone to a augmenting path, then build residual network, keep looking augmenting path in the residual network ..... can not be found until the cumulative flow rate is maximum (the specific principles can be cut by a minimum prove))

#include <iostream>
using namespace std;
const int N =1000;
const int M =10000;
int h[N],to[M],ne[M],cap[M],vi[N]idx=0; void add(int a,int b,int w){ to[idx]=b; ne[idx]=h[a]; cap[idx]=w; h[a]=idx++; } int dfs(int v,int t,int f){ if(v==t)returnF; VI [V] = . 1 ; for ( int I = H [V]; ~ I; I = NE [I]) { int TEM = to [I]; IF ([TEM] VI && CAP [I]>! 0 ) { int D = DFS (TEM, T, min (F, CAP [I])); IF (D> 0 ) { // If it detects a flow rate of greater than 0 then stopped CAP [I] - = D; // I reverse side. 1 + CAP [I + . 1 ] + = D; return D; } } } return 0; } int max_f(int s,int t){ int flow=0; while(true){ memset(vi,-1,sizeof(vi)); int f=dfs(s,t,0x3f); if(f==0)return flow; flow+=f; } }

 

Guess you like

Origin www.cnblogs.com/kstranger/p/12300767.html