QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#823146#9810. Obliviate, Then ReincarnateTJUHuangTaoWA 3ms12028kbC++232.3kb2024-12-20 19:47:412024-12-20 19:47:47

Judging History

This is the latest submission verdict.

  • [2024-12-20 19:47:47]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 12028kb
  • [2024-12-20 19:47:41]
  • 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;
            dfs(v);
        } else {
            if (val[v] != val[u] + w)
                z = 0;
        }
    }
}
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 = 1; i <= cscc; i++) {
        z = 1;
        for (auto u : vec[i]) {
            if (!vis[u]) {
                vis[u] = 1;
                val[u] = 0;
                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]] == 0)
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11732kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 3ms
memory: 11732kb

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 11740kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 12028kb

input:

3 2 3
0 1000000000
1 -1000000000
-1000000000
0
-1000000000

output:

No
Yes
No

result:

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