二分图最大匹配.
#include <stdio.h>
#include <string.h>
#define MAX 505
bool map[MAX][MAX];
bool visited[MAX];
int match[MAX];
int k, n, m;
bool dfs(int v) {
int i;
for (i = 1; i <= m; i++) {
if (map[v][i] && !visited[i]) {
visited[i] = true;
if (match[i] == -1 || dfs(match[i])) {
match[i] = v;
return true;
}
}
}
return false;
}
int main() {
int i;
int a, b;
int ans;
while (scanf("%d", &k) != EOF && k) {
memset(map, false, sizeof(map));
for (i = 0; i < MAX; i++) {
match[i] = -1;
}
scanf("%d%d", &n, &m);
for (i = 0; i < k; i++) {
scanf("%d%d", &a, &b);
map[a][b] = true;
}
ans = 0;
for (i = 1; i <= n; i++) {
memset(visited, false, sizeof(visited));
if (dfs(i)) {
ans++;
}
}
printf("%d\n", ans);
}
return 0;
}