1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <bits/stdc++.h> using namespace std; const int LEN = 5e5 + 50, MOD = 80112002; int n, m, f[LEN], ind[LEN], outd[LEN]; queue<int> q; vector<int> e[LEN];
void toposort() { for (int i = 1; i <= n; ++i) if (ind[i] == 0) { q.emplace(i); f[i] = 1; } while (!q.empty()) { int x = q.front(); q.pop(); for (int i = 0; i < e[x].size(); ++i) { int y = e[x][i]; f[y] = (f[y] + f[x]) % MOD; if (--ind[y] == 0) q.emplace(y); } } }
int main() { int x, y; cin >> n >> m; for (int i = 1; i <= m; ++i) { cin >> x >> y; e[x].emplace_back(y); ++outd[x], ++ind[y]; } toposort(); int ans = 0; for (int i = 1; i <= n; ++i) { if (outd[i] == 0) ans = (ans + f[i]) % MOD; } cout << ans; return 0; }
|