比较简单。
#include#include #include #define maxn 110#define INF 99999999using namespace std;int vis[maxn],n,map[maxn][maxn];int min(int x,int y){ return x 0) { a=dfs(i,min(low,map[u][i])); if(!a)continue; map[u][i]-=a; map[i][u]+=a; return a; } } return 0;}bool BFS(){ int i; queue q; memset(vis,-1,sizeof(vis)); vis[0]=0; q.push(0); while(!q.empty()) { int t=q.front(); q.pop(); for(i=0;i<=n+1;i++) { if(vis[i]<0&&map[t][i]>0) { vis[i]=vis[t]+1; q.push(i); } } } if(vis[n+1]>0)return true; return false;}int main(){ int i,nc,np,m; while(scanf("%d %d %d %d",&n,&np,&nc,&m)!=EOF) { memset(map,0,sizeof(map)); for(i=0;i