全wa看不出哪里错了 求助
查看原帖
全wa看不出哪里错了 求助
1021623
AVLw楼主2023/10/20 18:26

我看一直不对就基本都搬题解了 还是不对又看不出来了 。 调完回大佬关注

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

const int N = 1e5 + 10, mod = 80112002;
int ind[N], outd[N], f[N];
vector<int> e[N];
queue<int> q;

int main() {
    int n, m;
    int ans = 0;
   
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);  //a->b
        outd[a]++;
        ind[b]++;
        e[a].push_back(b);
    }

    for (int i = 1; i <= n; i++) {
        if (ind[i] == 0)
            q.push(i);
        f[i] = 1;
    }

    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (auto y : e[x]) {
            f[y] = (f[x] + f[y]) % mod;
            if (--ind[y] == 0)
                q.push(y);
        }
    }

    for (int i = 1; i <= n; i++) {
        if (outd[i] == 0)
            ans = (ans + f[i]) % mod;
    }

    printf("%d\n", ans);
    return 0;
}

2023/10/20 18:26
加载中...