poj 3041 Asteroids

http://poj.org/problem?id=3041

 

 

View Code
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int map[510][510] = {0};
int match[510] = {0};
int value[510] = {0};
int n = 0;
int m = 0;
int x = 0;
int y = 0;
int find(int q)
{
for(int i = 1;i <= n; ++i)
{
if(value[i] == 0 &&map[q][i])
{
value[i] = 1;
if(match[i] == -1||find(match[i]))
{
match[i] = q;
return 1;
}
}
}
return 0;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(map,0,sizeof(map));
memset(match,-1,sizeof(match));
for(int i = 1;i <= m;++i)
{
scanf("%d%d",&x,&y);
map[x][y] = 1;
}
int ans = 0;
for(int i = 1;i <= n;++i)
{
memset(value,0,sizeof(value));
if(find(i))
++ans;
}
printf("%d\n",ans);
}
return 0;
}



posted @ 2012-03-14 22:13  LT-blogs  阅读(142)  评论(0编辑  收藏  举报