二分图应用模版
#include #include #include #include #include #include using namespace std;const int MAXN=400,MAXM=50005;int head[MAXN],nume,n,m,maxflow,s,t,cur[MAXN],dep[MAXN];queue q;struct edge{ int to,nxt,cap,flow;}e[MAXM];void adde(int from,int to,int cap){ e[++nume].to=to; e[nume].cap=cap; e[nume].nxt=head[from]; head[from]=nume;}bool bfs(){ memset(dep,0,sizeof(dep)); q.push(s);dep[s]=1; while(!q.empty()){ int u=q.front();q.pop(); for(int i=head[u];i;i=e[i].nxt){ int v=e[i].to; if(!dep[v]&&e[i].flow >n>>m; s=0;t=n*2+1; for(int i=1;i<=m;i++){ int u,v; scanf("%d%d",&u,&v); adde(u,v+n,1);adde(v+n,u,0); } for(int i=1;i<=n;i++){ adde(s,i,1);adde(i,s,0); adde(i+n,t,1);adde(t,i+n,0); } dinic(); for(int i=1;i<=n;i++){ if(!f[i]) print(i),printf("\n"); } printf("%d\n",n-maxflow);}