枚举法求解最大流

#include <iostream>
using namespace std;
int vis[100];
int c[3][3]={0 , 1, 2, 0 ,0 , 4, 0 , 0 , 0};
int flow=0;
int sink;
int s;
int n;
int dfs(int x,int low)
{
if (x==sink)return low;
if (vis [x])return 0;
vis [x]=true;
for(int i=0,flow;i<n;i++)
if (c[x ][ i]&&(flow=dfs(i,low <?c[x][i])))
{
c[x][i]-=flow; c[i][x]+=flow;
return flow;
}
return 0;
}

int maxflow() {
int ans=0,flow; memset(vis,0,sizeof(vis)) ;
while(flow=dfs(s,2147483647)){memset(vis,0,sizeof(vis));ans+=flow;}
return ans;
}

int main()
{
   
    n=3;
    sink=2;
    s=0;
    cout<<maxflow()<<endl;
    system("pause");
}
// !!!!!!!!!!!!!rigth!!!!!!!!!!!!!!!!!!!!!

你可能感兴趣的:(枚举法求解最大流)