#include<iostream> #include<cstdio> #include<cstring> #define maxn 2020 using namespace std; int n,m,g[maxn][maxn],ans,f[maxn],match[maxn]; int init() { int x=0;char s;s=getchar(); while(s<‘0‘||s>‘9‘)s=getchar(); while(s>=‘0‘&&s<=‘9‘){x=x*10+s-‘0‘;s=getchar();} return x; } int Dfs(int s) { for(int i=1;i<=n;i++) if(g[s][i]&&f[i]==0) { f[i]=1; if(match[i]==0||Dfs(match[i])) { match[i]=s; return 1; } } return 0; } int main() { n=init();m=init(); int x,y; for(int i=1;i<=m;i++) { x=init();y=init(); g[x][y]=1; } for(int i=1;i<=n;i++) { memset(f,0,sizeof(f)); ans+=Dfs(i); } printf("%d\n",n-ans); return 0; }
时间: 2024-10-25 05:37:58