View Code
#include<stdio.h>
#include<string.h>
bool map[505][505];
int men[505];
bool hash[505];
int m;
bool dfs(int x)
{
int i;
for(i=1;i<=m;i++)
{
if(map[x][i]==0||hash[i]) continue;
hash[i]=1;
if(men[i]==0||dfs(men[i]))
{
men[i]=x;
return 1;
}
}
return 0;
}
int main()
{
int i,g,k;
int count;
while(scanf("%d",&k),k)
{
scanf("%d%d",&g,&m);
memset(map,0,sizeof(map));
for(i=0;i<k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
map[x][y]=1;
}
memset(men,0,sizeof(men));
count=0;
for(i=1;i<=g;i++)
{
memset(hash,0,sizeof(hash));
if(dfs(i)==1) count++;
}
printf("%d\n",count);
}
}