#include <bits/stdc++.h>
using namespace std;
int n, m, t[100005], ans = 0, ans1[100005];
vector <int> a[100005];
queue <int> b;
void dfs(int x)
{
if (a[x].size() == 0 && t[x] != 0)
{
ans++;
return;
}
for (auto y : a[x])
dfs(y);
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int xx, yy;
cin >> xx >> yy;
t[yy] ++;
a[xx].push_back(yy);
}
for (int i = 1; i <= n; i++)
{
if (t[i] == 0)
b.push(i);
}
while (b.size())
{
int xx = b.front();
b.pop();
dfs(xx);
}
cout << ans;
return 0;
}
大佬们,dfs70分怎么优化啊