题目传送门:https://www.luogu.com.cn/problem/P4017
代码:
1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<vector>
5 #include<map>
6 #include<queue>
7 #include<set>
8 #include<cmath>
9 #include<list>
10 #include<cstring>
11 #include<string>
12 #define ll long long
13 #define ull unsigned long long
14 #define inf 0x3f3f3f3f
15 #define inff 0x7fffffff
16 using namespace std;
17 const int N = 5000 + 10;
18 const int mod = 80112002;
19
20 vector<int>G[N];
21 int in[N], val[N], out[N];
22 int n, m;
23
24 void topo() {
25
26 queue<int>q;
27 for (int i = 1; i <= n; i++) {
28 if (!in[i]) {
29 q.push(i);
30 val[i] = 1;
31 }
32 }
33 while (!q.empty()) {
34 int tmp = q.front();
35 q.pop();
36 for (int i = 0; i < G[tmp].size(); i++) {
37 int to = G[tmp][i];
38 in[to]--;
39 val[to] = (val[tmp] + val[to]) % mod;
40 if (in[to] == 0) q.push(to);
41 }
42 }
43
44 return;
45 }
46
47 int main() {
48
49 //int n, m;
50 cin >> n >> m;
51 for (int i = 1; i <= m; i++) {
52 int u, v;
53 cin >> u >> v;
54 G[u].push_back(v);
55 in[v]++;
56 out[u]++;
57 }
58 int ans = 0;
59 topo();
60 for (int i = 1; i <= n; i++) {
61 if (!out[i]) ans = (ans + val[i]) % mod;
62 }
63 cout << ans << "\n";
64
65 return 0;
66 }