#include<cstdio> #include<cstring> #include<algorithm> #define ll int #define N 105 using namespace std; inline ll read(){ char ch=getchar(); ll x=0,f=1; while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); } while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } struct edge{ ll to,next; }e[N*N*2]; ll head[N],flag[N],link[N],f[N][N]; ll n,m,tot,ans; void add(ll u,ll v){ e[++tot]=(edge){v,head[u]}; head[u]=tot; } bool find(ll u){ for (ll i=head[u],v=e[i].to;i;i=e[i].next,v=e[i].to) if (!flag[v]){ flag[v]=1; if (!link[v]||find(link[v])){ link[v]=u; return 1; } } return 0; } int main(){ n=read(); m=read(); for (ll i=1;i<=m;i++){ ll u=read(),v=read(); f[u][v]=1; } for (ll k=1;k<=n;k++) for (ll i=1;i<=n;i++) for (ll j=1;j<=n;j++) f[i][j]|=f[i][k]&f[k][j]; for (ll i=1;i<=n;i++) for (ll j=1;j<=n;j++) if (f[i][j]&&i!=j) add(i,j); ans=n; for (ll i=1;i<=n;i++){ memset(flag,0,sizeof flag); if (find(i)) ans--; } printf("%d",ans); }
|