hhh
暴力72分,TLE3个点hhh
#include<bits/stdc++.h>
using namespace std;
int tot = 0;
int next[100005], first[100005], to[100005], vis[100005], n, m;
void add(int x, int y)
{
tot++;
next[tot] = first[x];
first[x] = tot;
to[tot] = y;
}
void dfs(int x)
{
if(vis[x] == 1)
{
return;
}
vis[x] = 1;
for(int i = first[x]; i; i = next[i])
{
int u = to[i];
dfs(u);
}
return;
}
int check()
{
for(int i = 1; i <= n; i++)
{
if(vis[i] == 0)
{
return 0;
}
}
return 1;
}
int main()
{
int ans = 0;
cin >> n >> m;
int a, b;
for(int i = 1; i <= m; i++)
{
cin >> a >> b;
add(b, a);
}
for(int i = 1; i <= n; i++)
{
memset(vis, 0, sizeof(vis));
dfs(i);
if(check())
{
ans++;
}
}
cout << ans;
return 0;
}