#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 510, M = 100010; int n1, n2, m; int h[N], e[M], ne[M], idx; int match[N]; bool st[N]; void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ; } bool find(int x) { for (int i = h[x]; i != -1; i = ne[i]) {//枚举所有看上的 int j = e[i]; if (!st[j]) {//如果没考虑过 st[j] = true;//表示考虑过了 //如果这个妹子还没匹配其他男生 ,或者说虽然已经匹配了,但可以给那个男生找到下家 if (match[j] == 0 || find(match[j])) { match[j] = x; return true; } } } return false; } int main() { scanf("%d%d%d", &n1, &n2, &m); memset(h, -1, sizeof h); while (m -- ) { int a, b; scanf("%d%d", &a, &b); add(a, b); } int res = 0;//匹配的数量 for (int i = 1; i <= n1; i ++ ) {//依次看每个男生 memset(st, false, sizeof st);//先把所以的妹子清空,表示都还没考虑过 if (find(i)) res ++ ;//如果成功过找到,就加一 } printf("%d ", res); return 0; }