显示代码纯文本
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int maxn=5010;
int n,m,cx[maxn],cy[maxn];
bool a[maxn][maxn],vis[maxn];
void Init();
int path(int x){
for(int i=1;i<=n;i++){
if(a[x][i] && !vis[i]){
vis[i]=1;
if(cy[i]==0 || path(cy[i])){
cx[x]=i;cy[i]=x;
return 1;
}
}
}
return 0;
}
int main(){
freopen("chbtrip.in","r",stdin);
freopen("chbtrip.out","w",stdout);
Init();
return 0;
}
void Init(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
x++;y++;a[x][y]=1;
}
int ans=0;
for(int i=1;i<=n;i++){
if(cx[i]==0){
memset(vis,0,sizeof(vis));
ans+=path(i);
}
}
printf("%d\n",n-ans);
//system("pause");
}