#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
const int maxn=510;
using namespace std;
int my[maxn],mx[maxn],vis[maxn],e[maxn][maxn],n;
int path(int i)
{
int j;
for(j=1;j<=n;j++)
{
if(e[i][j]&&!vis[j])
{
vis[j]=1;
if(my[j]==-1||path(my[j]))
{
my[j]=i;
mx[i]=j;
return 1;
}
}
}
return 0;
}
int hungry()
{
int i,res=0;
memset(mx,-1,sizeof mx);
memset(my,-1,sizeof my);
for(i=1;i<=n;i++)
{
if(mx[i]==-1)
{
memset(vis,0,sizeof vis);
res+=path(i);
}
}
return res;
}
int main()
{
int a,b,k;
while(~scanf("%d%d",&n,&k))
{
memset(e,0,sizeof e);
while(k--)
{
scanf("%d%d",&a,&b);
e[a][b]=1;
}
printf("%d\n",hungry());
}
return 0;
}
poj3041 Asteroids --- 最小点覆盖,布布扣,bubuko.com
原文地址:http://blog.csdn.net/u011032846/article/details/38024039