| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
3 4 1 1 1 3 2 2 3 2
Sample Output
2
Hint
Source
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n, k;
int g[505][505], linker[505], vis[505];
int Find(int x)
{
for(int i = 1;i <= n;i ++)
{
if(!vis[i] && g[x][i])
{
vis[i] = 1;
if(linker[i] == 0 || Find(linker[i]))
{
linker[i] = x;
return 1;
}
}
}
return 0;
}
int main()
{
int a, b, ans;
while(scanf("%d%d", &n, &k) != EOF)
{
ans = 0;
memset(g, 0, sizeof(g));
memset(linker, 0, sizeof(linker));
while(k --)
{
scanf("%d%d",&a, &b);
g[a][b] = 1;
}
for(int i = 1;i <= n;i ++)
{
memset(vis, 0, sizeof(vis));
if(Find(i)) ans ++;
}
printf("%d\n",ans);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/mowenwen_/article/details/47839929