作者:
wyc1996
,
2020-12-16 11:40:43
,
阅读 18
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=210,M=30010;
int n,m;
bool d[N][N],st[N];
int match[N];
bool find(int x)
{
for(int i=1;i<=n;i++){
if(d[x][i] && !st[i]){
st[i]=true;
int t=match[i];
if(t==0 || find(t)){
match[i]=x;
return true;
}
}
}
return false;
}
int main()
{
scanf("%d%d",&n,&m);
while(m--){
int a,b;
scanf("%d%d",&a,&b);
d[a][b]=true;
}
//先将整个图的传递闭包求出来
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
d[i][j]|=d[i][k]&d[k][j];
//求最大匹配
int res=0;
for(int i=1;i<=n;i++){
memset(st,0,sizeof st);
if(find(i))res++;
}
printf("%d\n",n-res);
return 0;
}