QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795086#9810. Obliviate, Then ReincarnateLegend_dy#WA 4ms16172kbC++202.6kb2024-11-30 17:49:542024-11-30 17:49:56

Judging History

This is the latest submission verdict.

  • [2024-11-30 17:49:56]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 16172kb
  • [2024-11-30 17:49:54]
  • Submitted

answer

#include <bits/stdc++.h>

#define int long long

using namespace std;

constexpr int N = 1e6 + 5, M = 1e6 + 5;

int ver[M], Next[M], head[N], dfn[N], low[N];
int s[N], ins[N], c[N];
vector<int> scc[N];
int tot, num, top, cnt;

void add(int x, int y) {
    ver[++tot] = y, Next[tot] = head[x], head[x] = tot;
}

void tarjan(int x) {
    dfn[x] = low[x] = ++num;
    s[++top] = x, ins[x] = 1;
    for (int i = head[x]; i; i = Next[i]) {
        if (!dfn[ver[i]]) {
            tarjan(ver[i]);
            low[x] = min(low[x], low[ver[i]]);
        }
        else if (ins[ver[i]]) {
            low[x] = min(low[x], dfn[ver[i]]);
        }
    }
    if (dfn[x] == low[x]) {
        cnt++;
        int y;
        do {
            y = s[top--], ins[y] = 0;
            c[y] = cnt, scc[cnt].push_back(y);
        } while (x != y);
    }
}

void solve() {  
    int n, m, t;
    cin >> n >> m >> t;

    vector<int> vis(n);
    for (int i = 1, a, b; i <= m; i++) {
        cin >> a >> b;
        if (b == 0) continue;
        a = (a % n + n) % n;
        b = (b % n + n) % n;
        add(a, (a + b) % n);
        if (a == (a + b) % n) {
            vis[a] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        if (!dfn[i]) tarjan(i);
    }

    vector<int> d(cnt + 1);
    vector g(cnt + 1, vector<int>());
    for (int x = 0; x < n; x++) {
        for (int i = head[x]; i; i = Next[i]) {
            int y = ver[i];
            if (c[x] == c[y]) continue;
            g[c[y]].push_back(c[x]); // 建反边
            // cerr << c[y] << " " << c[x] << "\n"; 
            d[c[x]]++;
        }
    } 

    queue<int> q;
    for (int i = 1; i <= cnt; i++) {
        if (scc[i].size() > 1) {
            for (auto x : scc[i]) {
                vis[x] = 1;
                // cerr << x << "!!!\n";
            }
        }
        if (!d[i]) {
            q.push(i);
            // cerr << i << "!\n";
        }
    }

    while (!q.empty()) {
        auto u = q.front();
        q.pop();
        for (auto v : g[u]) {
            int x = scc[u][0];
            if (!vis[scc[v][0]] && vis[x]) for (auto y : scc[v]) {
                vis[y] |= vis[x];
            }
            d[v]--;
            if (!d[v]) q.push(v);
        }
    }

    while (t--) {
        int x;
        cin >> x;

        x = (x % n + n) % n;

        if (vis[x]) {
            cout << "Yes\n";
        }
        else cout << "No\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T = 1;
    // cin >> T;

    while(T--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 16172kb

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: 4ms
memory: 15952kb

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: 16104kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

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

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'