以前刷试炼场时根本不会的
现在 一眼最小割!
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#define MAXN 1000000
#define INF 100000000
using namespace std;
int n,m,s,t;
int tot=2,g[MAXN],num[MAXN],nnext[MAXN],flow[MAXN];
int team[MAXN],head,tail,d[MAXN];
void Add(int x,int y,int z){nnext[tot]=g[x];g[x]=tot;num[tot]=y;flow[tot]=z;tot++;}
bool bfs()
{
head=tail=0;memset(d,0,sizeof(d));
d[s]=1;team[++tail]=s;
while(head<tail)
{
int x=team[++head];
for(int i=g[x];i;i=nnext[i])
if(d[num[i]]==0&&flow[i]!=0)
d[num[i]]=d[x]+1,team[++tail]=num[i];
}
if(d[t]==0) return false;
return true;
}
int dfs(int x,int mmin)
{
if(x==t) return mmin;
int tmp,f=0;
for(int i=g[x];i;i=nnext[i])
if(d[num[i]]==d[x]+1&&flow[i]&&(tmp=dfs(num[i],min(mmin,flow[i]))))
{
flow[i]-=tmp,flow[i^1]+=tmp;
f+=tmp,mmin-=tmp;
if(mmin==0) return f;
}
return f;
}
int main()
{
scanf("%d %d %d %d",&n,&m,&s,&t);
for(int x,y,i=1;i<=m;i++)
{
scanf("%d %d",&x,&y);
Add(x+n,y,INF),Add(y,x+n,0);
Add(y+n,x,INF),Add(x,y+n,0);
}
for(int i=1;i<=n;i++) Add(i,i+n,1),Add(i+n,i,0);
int ans=0;while(bfs()) ans+=dfs(s+n,INF);
printf("%d\n",ans);
return 0;
}