1 条题解

  • 0
    @ 2022-12-22 20:12:24
    #include <bits/stdc++.h>
    using namespace std;
    int n, m, ans;
    int in[5005], out[5005];
    int dp[5005];
    vector<int> e[5005];
    queue<int> zero;
    int main()
    {
        cin >> n >> m;
        for (int i = 1; i <= m; i++)
        {
            int u, v;
            cin >> u >> v;
            e[u].push_back(v);
            in[v]++;
            out[u]++;
        }
        for (int i = 1; i <= n; i++)
            if (in[i] == 0)
            {
                dp[i] = 1;
                zero.push(i);
            }
        for (int t = 1; t <= n; t++)
        {
            int u = zero.front();
            zero.pop();
            for (int i = 0; i < e[u].size(); i++)
            {
                int v = e[u][i]; // u -> v
                in[v]--;
                if (in[v] == 0)
                    zero.push(v);
                dp[v] = (dp[v] + dp[u]) % 80112002;
            }
        }
        for (int i = 1; i <= n; i++)
            if (out[i] == 0)
                ans = (ans + dp[i]) % 80112002;
        cout << ans << endl;
        return 0;
    }
    
    • 1

    信息

    ID
    1200
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    22
    已通过
    22
    上传者