// #pragma GCC optimize(3) #include<bits/stdc++.h> usingnamespace std; constint N = 1e5 + 10, M = 2e5 + 10; int in[N], out[N], x, y, n, m, pre[N], clonein[N], k; int dp[N]; structnode { int to, nxt; } a[M];
voidadd(int u, int v){ a[++k] = {v, pre[u]}; pre[u] = k; } intmain(){ // ios::sync_with_stdio(false); // cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> x >> y; add(x, y); in[y]++; clonein[y]++; out[x]++; } queue<int> q; for (int i = 1; i <= n; i++) { if (in[i] == 0) { q.push(i); dp[i] = 1; } } while (!q.empty()) { int h = q.front(); q.pop(); for (int i = pre[h]; i; i = a[i].nxt) { int to = a[i].to; dp[to] += dp[h]; in[to]--; if (in[to] == 0) { q.push(to); } } } int tot = 0; for (int i = 1; i <= n; i++) { if (clonein[i] != 0and out[i] == 0) { tot += dp[i]; } } cout << tot << endl; return0; }