#1输出答案明明是对的却给我判错??
查看原帖
#1输出答案明明是对的却给我判错??
1112952
Au_Gold楼主2024/5/30 21:24
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 5000 + 5,mod = 80112002;

ll n, m,ind[N],ans[N];
vector<ll> e[N],fin,sta;

ll dfs(ll st) {
    if(ans[st])
        return ans[st];

    if(st ==*lower_bound(fin.begin(),fin.end(),st)) {
        return 1;
    }

    for (auto p = e[st].begin(); p != e[st].end();p++) {
        ll to = *p;
        ans[st] += dfs(to);
    }
    ans[st] %= mod;

    return ans[st];
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m;i++) {
        ll fr, to;
        cin >> fr >> to;
        e[fr].push_back(to);
        ind[to]++;
    }
    for (int i = 1; i <= n;i++) {//入度为0的点为起点
        if(!ind[i])
            sta.push_back(i);
    }
    for (int i = 1; i <= n;i++) {//出度为0的点为终点
        if (e[i].empty())
            fin.push_back(i);
    }

    ll anss = 0;
    for (auto p = sta.begin(); p != sta.end();p++) {
        ll st = *p;
        dfs(st);
        anss += ans[st];
        anss %= mod;
    }

    //cout << anss << endl;
    printf("%lld", anss);

    return 0;
}
2024/5/30 21:24
加载中...