题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063
题意:中文题
解析:二分图匹配裸题
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
struct node
{
int to,next;
}edge[maxn];
int head[maxn],cnt;
int match[maxn],vis[maxn];
void init()
{
memset(head,-1,sizeof(head));
memset(match,0,sizeof(match));
cnt = 0;
}
void addEdge(int from,int to)
{
edge[cnt].to = to;
edge[cnt].next = head[from];
head[from] = cnt++;
}
bool dfs(int u)
{
for(int i=head[u];i!=-1;i = edge[i].next)
{
int v = edge[i].to;
if(vis[v]) continue;
vis[v] = 1;
if(!match[v] || dfs(match[v]))
{
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int main(void)
{
int k;
while(~scanf("%d",&k)&&k)
{
int n,m;
init();
scanf("%d %d",&m,&n);
for(int i=0;i<k;i++)
{
int x,y;
scanf("%d %d",&x,&y);
addEdge(x,y+m);
}
int ans = 0;
for(int i=1;i<=m;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",ans);
}
return 0;
}