二分图(匈牙利算法)
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MAXN = 510;
int line[MAXN][MAXN];
int used[MAXN];
int nxt[MAXN];
int n,m;
bool Find(int x) {
for (int i = 1;i <= m;i ++){
if (line[x][i] && !used[i]){
used[i] = 1;
if (nxt[i] == 0 || Find(nxt[i])){
nxt[i] = x;
return true;
}
}
}
return false;
}
int match() {
int sum = 0;
for (int i = 1;i <= n;i ++){
memset(used,0,sizeof(used));
if (Find(i)) sum ++;
}
return sum;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T;
while (cin >> T,T){
cin >> n >> m;
memset(line,0,sizeof(line));
memset(nxt,0,sizeof(nxt));
int x,y;
for (int i = 1;i <= T;i ++){
cin >> x >> y;
line[x][y] = 1;
}
cout << match() << endl;
}
}