https://www.acwing.com/problem/content/description/863/
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int h[N],e[N*2],ne[N*2],idx;
int match[N];
bool vis[N];
void add(int a,int b){
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
int n1,n2,m;
bool find(int u){
for(int i=h[u];i!=-1;i=ne[i]){
int j=e[i];
if(!vis[j]){
vis[j]=true;
if(match[j]==0||find(match[j])){
match[j]=u;
return true;
}
}
}
return false;
}
int main(){
memset(h,-1,sizeof h);
cin>>n1>>n2>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
add(a,b);
}
int res=0;
for(int i=1;i<=n1;i++){
memset(vis,false,sizeof vis);
if(find(i)) res++;
}
cout<<res<<endl;
return 0;
}
posted on
浙公网安备 33010602011771号