#include<bits/stdc++.h>
using namespace std;
vector<int> g[505];
int n,m,e;
int vis[505],match[505];
inline bool dfs(int fr,int dif){
if(vis[fr]==dif) return false;
vis[fr]=dif;
for(int i:g[fr]){
if(!match[i]||dfs(i,dif)){
match[i]=fr;
return true;
}
}
return false;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m>>e;
while(e--){
int u,v;
cin>>u>>v;
g[u].push_back(v);
}
int ans=0;
for(int i=1;i<=n;i++){
if(dfs(i,i)) ans++;
}
cout<<ans<<endl;
return 0;
}
这个点过不了:
Input
5 5 9
3 5
5 5
5 5
5 3
1 3
1 4
4 1
5 5
3 5
Ans
4
My_output
3