poj1149最大流
2024-07-14 10:22:19 226人阅读
#include <cstdio>#include <cstring>#include <algorithm>#include <climits>#include <string>#include <iostream>#include <map>#include <cstdlib>#include <list>#include <set>#include <queue>#include <stack>using namespace std;const int INF=0xfffffff;int n,m;const int maxn=1111;int level[maxn];int Map[maxn][maxn];int last[maxn];int s,e;int pig[maxn];bool bfs(){ memset(level,0,sizeof(level)); queue<int> q; q.push(s);level[s]=1; while(!q.empty()){ int cur=q.front();q.pop(); for(int i=0;i<=n+1;i++){ if(!level[i]&&Map[cur][i]){ level[i]=level[cur]+1; q.push(i); } } } return level[e];}int Min(int a,int b){ return a>b?b:a;}int dfs(int x,int val){ int tem=val; if(x==e) return val; for(int i=0;i<=n+1;i++){ if(level[i]==level[x]+1&&Map[x][i]&&tem){ int t=dfs(i,Min(val,Map[x][i])); Map[x][i]-=t;Map[i][x]+=t;