#include<bits/stdc++.h>
using namespace std;
const int N=5e5+4;
int n,m;
int h[N],to[N*2],nt[N*2],cnt;
void add(int x,int y){
nt[++cnt]=h[x];
h[x]=cnt;
to[cnt]=y;
}
int match[N];
int vis[N];
bool dfs(int x)
{
for(int i=h[x]; i; i=nt[i])
{
int y=to[i];
if(vis[y])continue;
vis[y]=1;
if(match[y]==0||dfs(match[y]))
{
match[y]=x;
return true;
}
}
return false;
}
int e,ans;
int main(){
//freopen("text.in","r",stdin);
cin>>n>>m>>e;
for(int i=1; i<=e; i++){
static int x,y;
cin>>x>>y;
add(x,y);
}
for(int i=1; i<=n; i++){
memset(vis,0,sizeof(vis));
if(dfs(i))ans++;
}
cout<<ans<<endl;
}
标签:二分,cnt,vis,int,dfs,P3386,模板,nt,match
From: https://www.cnblogs.com/dadidididi/p/16805345.html