QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#823166#9810. Obliviate, Then ReincarnateTJUHuangTaoWA 3ms11760kbC++232.3kb2024-12-20 19:59:572024-12-20 19:59:59

Judging History

This is the latest submission verdict.

  • [2024-12-20 19:59:59]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 11760kb
  • [2024-12-20 19:59:57]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
using namespace std;
const int maxn = 5e5 + 10;
vector<pii> G[maxn];
vector<int> vec[maxn];
stack<int> stk;
int dfn[maxn], low[maxn], instk[maxn], scc[maxn], cscc, Cnt;
int dp[maxn];
void tarjan(int u) {
    low[u] = dfn[u] = ++Cnt;
    instk[u] = 1;
    stk.push(u);
    for (auto [v, w] : G[u]) {
        if (!dfn[v]) {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        } else if (instk[v])
            low[u] = min(low[u], dfn[v]);
    }
    if (low[u] == dfn[u]) {
        int top;
        cscc++;
        do {
            top = stk.top();
            stk.pop();
            instk[top] = 0;
            scc[top] = cscc;
            vec[cscc].push_back(top);
        } while (top != u);
    }
}
int z;
int vis[maxn], val[maxn];
void dfs(int u) {
    for (auto [v, w] : G[u]) {
        if (!vis[v]) {
            val[v] = val[u] + w;
            vis[v] = 1;
            dfs(v);
        } else {
            if (val[v] != val[u] + w)
                z = 1;
        }
    }
}
void solve() {
    int n, m, Q;
    cin >> n >> m >> Q;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        if (b == 0)
            continue;
        a = (a % n + n) % n;
        int v = (a + b % n + n) % n;
        G[a].emplace_back(v, b);
    }
    for (int i = 0; i < n; i++)
        if (!dfn[i])
            tarjan(i);
    for (int i = cscc; i; i--) {
        z = 0;
        for (auto u : vec[i]) {
            if (!vis[u]) {
                vis[u] = 1;
                dfs(u);
            }
        }
        dp[i] = z;
    }
    for (int i = cscc; i; i--) {
        for (auto u : vec[i])
            for (auto [v, w] : G[u]) {
                if (scc[u] != scc[v]) {
                    dp[scc[u]] |= dp[scc[v]];
                }
            }
    }
    while (Q--) {
        int x;
        cin >> x;
        x = (x % n + n) % n;
        if (dp[scc[x]])
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 11760kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
No
No

result:

wrong answer 2nd words differ - expected: 'Yes', found: 'No'