显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,a[110][110]={0},ans=0;
int main()
{
freopen("contest.in","r",stdin);
freopen("contest.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
a[i][j]=9999999;
for(int i=1;i<=m;++i)
{
int t1,t2;
scanf("%d%d",&t1,&t2);
a[t1][t2]=1;
//a[t2][t1]=1;
}
for(int k=1;k<=n;++k)
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
/*
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
printf("%d ",a[i][j]);
printf("\n");
}
*/
for(int i=1;i<=n;++i)
{
int t1=0;
for(int j=1;j<=n;++j)
if(a[i][j]!=9999999||a[j][i]!=9999999)
++t1;
if(t1==n-1)
++ans;
}
printf("%d\n",ans);
return 0;
}