题目链接:
https://www.luogu.com.cn/problem/P3386
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <set>
#define ll long long
#define rep(i,a,n) for(ll i = a; i <= n; i ++)
#define per(i,a,n) for(ll i = n; i >= a; i --)
#define pb push_back
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define PII std::pair<ll,ll>
const ll N = 1e5 + 10;
const ll mod = 998244353;
//const ll mod = 1e9 + 7;
//注:1073741823的二进制全是1
//bool dp[N][N];
bool ff[N];
ll mm[N];
ll k,m,n;
ll op[N];//op[a] = b;表示a这个人已经与b进行配对了
ll res = 0;
ll e[N],ne[N],idx,h[N];
void add(ll a,ll b){
e[idx] = b;
ne[idx] = h[a];
h[a] = idx ++;
}
bool dfs(ll xx){//如何返回
for(ll i = h[xx]; i != -1; i = ne[i]){
// std::cout << "进去了" << "\n";
ll gg = e[i];
if(ff[gg] == false){
ff[gg] = true;//为什么能够在前面写,因为如果能那必然是true
if(dfs(mm[gg]) || mm[gg] == -1){//如果说有人让出来,或者原本就是还没有匹配的
mm[gg] = xx;//直接匹配
return true;
}
}
}
return false;
}
void solve(){
std::cin >> m >> n >> k;
std::memset(h,-1,sizeof h);
while(k --){
ll a,b;
std::cin >> a;
std::cin >> b;
add(a,b);
}
// std::cin >> k;
std::memset(mm,-1,sizeof mm);
rep(i,1,m){//这是往后面遍历
std::memset(ff,false,sizeof ff);
if(dfs(i)) res += 1;
}
std::cout << res << "\n";
return;
}
int main(){
IOS
ll t = 1;
while(t --)
solve();
return 0;
}