模版-匈牙利算法
#include <cstdio>
#include <cstring>
#include <iostream>
const int Maxn = 100005;
struct EDGE {
int v, next;
} e[Maxn << 2];
int head[Maxn], tot = 1;
bool vis[Maxn];
int p[Maxn];
void add(int u, int v) {
e[tot].v = v;
e[tot].next = head[u];
head[u] = tot++;
}
bool match(int x) {
for (int i = head[x]; i; i = e[i].next) {
int v = e[i].v;
if (!vis[v]) {
vis[v] = true;
if (p[v] == 0 || match(p[v])) {
p[v] = x;
return true;
}
}
}
return false;
}
int main() {
int n, m, ne;
scanf("%d %d %d", &n, &m, &ne);
int u, v;
for (int i = 0; i < ne; i++) {
scanf("%d %d", &u, &v);
add(u, v);
}
int res = 0;
for (int i = 1; i <= n; i++) {
memset(vis, 0,sizeof vis);
res += match(i);
}
printf("%d", res);
return 0;
}