QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497952#8728. Tablicaarbuzick#0 0ms0kbC++202.0kb2024-07-29 20:53:192024-07-29 20:53:23

Judging History

你现在查看的是最新测评结果

  • [2024-07-29 20:53:23]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-07-29 20:53:19]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

constexpr int mod = 1000000007;

constexpr int maxn = 405;

bitset<maxn> go[maxn];

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n), _g(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        _g[v].push_back(u);
    }
    for (int i = n - 1; i >= 0; --i) {
        go[i] = 0;
        for (auto j : g[i]) {
            go[i] |= go[j];
            go[i][j] = 1;
        }
    }
    int ans = 1;
    bitset<maxn> used = 0;
    for (int i = 0; i < n; ++i) {
        if (used[i]) {
            continue;
        }
        vector<int> used2(n);
        for (int j = 0; j < n; ++j) {
            if (go[i][j]) {
                if (!used[j]) {
                    ans = ans * 2LL % mod;
                } else if (!used2[j]) {
                    ans = ans * 2LL % mod;
                    used2[j] = 1;
                    queue<int> q;
                    q.push(j);
                    while (!q.empty()) {
                        int v = q.front();
                        q.pop();
                        for (auto u : g[v]) {
                            if (!used2[u]) {
                                used2[u] = 1;
                                q.push(u);
                            }
                        }
                        for (auto u : _g[v]) {
                            if (used[u] && !used2[u]) {
                                used2[u] = 1;
                                q.push(u);
                            }
                        }
                    }
                }
            }
        }
        used[i] = 1;
        used |= go[i];
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

5 6

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%