You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.1 KiB
58 lines
1.1 KiB
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 5010, M = 500010;
|
|
const int INF = 0x3f3f3f3f, MOD = 80112002;
|
|
|
|
int in[N], out[N], f[N];
|
|
int n, m;
|
|
|
|
//链式前向星
|
|
int e[M], h[N], idx, w[M], ne[M];
|
|
void add(int a, int b, int c = 0) {
|
|
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
|
|
}
|
|
|
|
void topsort() {
|
|
queue<int> q;
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
if (!in[i]) {
|
|
q.push(i);
|
|
f[i] = 1;
|
|
}
|
|
|
|
while (q.size()) {
|
|
int u = q.front();
|
|
q.pop();
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
int j = e[i];
|
|
in[j]--;
|
|
f[j] = (f[j] + f[u]) % MOD;
|
|
if (in[j] == 0) q.push(j);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
scanf("%d%d", &n, &m);
|
|
|
|
memset(h, -1, sizeof h);
|
|
|
|
while (m--) {
|
|
int a, b;
|
|
scanf("%d%d", &a, &b);
|
|
add(a, b);
|
|
in[b]++, out[a]++;
|
|
}
|
|
|
|
topsort();
|
|
|
|
int res = 0;
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
if (!out[i]) res = (res + f[i]) % MOD;
|
|
|
|
printf("%d", res);
|
|
return 0;
|
|
} |