poj 3041
774 ワード
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 505;
int g[maxn][maxn];
int n, k, r, c;
bool visit[maxn];
int mat[maxn];
int s;
int dfs(int id){
for(int i = 1; i <= n; ++i){
if(g[id][i] && !visit[i]){
visit[i] = true;
if(mat[i] == 0 || dfs(mat[i])){
mat[i] = id;
return 1;
}
}
}
return 0;
}
int main(){
scanf("%d%d",&n,&k);
for(int i = 0; i < k; ++i){
scanf("%d%d",&r, &c);
g[r][c] = 1;
}
for(int i = 1; i <= n; ++i){
memset(visit, 0, sizeof(visit));
if(dfs(i)){
++s;
}
}
printf("%d
",s);
return 0;
}