QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780893#9810. Obliviate, Then ReincarnatehhhyhWA 214ms47652kbC++232.3kb2024-11-25 13:53:052024-11-25 13:53:13

Judging History

This is the latest submission verdict.

  • [2024-11-26 23:19:26]
  • hack成功,自动添加数据
  • (/hack/1260)
  • [2024-11-25 13:53:13]
  • Judged
  • Verdict: WA
  • Time: 214ms
  • Memory: 47652kb
  • [2024-11-25 13:53:05]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
#define int long long
void solve()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> f(n), ok(n, 1);
    iota(all(f), 0ll);
    auto find = [&](auto find, int x) -> int
    {
        return f[x] == x ? f[x] : f[x] = find(find, f[x]);
    };
    vector<int> in(n), out(n);
    vector<vector<pair<int, int>>> e(n);
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        int w = b;
        a = (a % n + n) % n;
        if (b == 0)
            continue;
        b = (b % n + n) % n;
        b = (b + a) % n;
        e[a].push_back({b, w});
        g[b].push_back({a, w});
        in[b]++;
        out[a]++;
    }
    {
        queue<int> q;
        vector<i64> dep(n);
        vector<int> dfn(n), vis(n);
        int cnt = 0;
        function<void(int)> tarjan = [&](int x)
        {
            dfn[x] = ++cnt;
            vis[x] = 1;
            for (auto [y, w] : e[x])
            {
                if (vis[y])
                {

                    if (w + dep[x] - dep[y] != 0)
                        q.push(x);
                }
                else if (!dfn[y])
                {
                    dep[y] = dep[x] + w;
                    tarjan(y);
                }
            }
            vis[x] = 0;
        };
        for (int i = 0; i < n; i++)
            if (!dfn[i])
                tarjan(i);
        ok.assign(n, 0);
        while (!q.empty())
        {
            int x = q.front();
            q.pop();
            if (ok[x] != 0)
                continue;
            ok[x] = 1;
            for (auto [y, w] : g[x])
            {
                if (ok[y])
                    continue;
                ok[y] = 1;
                q.push(y);
            }
        }
    }
    for (int i = 0; i < q; i++)
    {
        int x;
        cin >> x;
        x = (x % n + n) % n;
        if (ok[x])
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    while (T--)
        solve();
}
/*
 3 2 3
 1 1
 -1 0
 1
 2
 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

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: 0ms
memory: 3872kb

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

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

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

input:

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

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 178ms
memory: 37964kb

input:

50134 500000 500000
-154428638 -283522863
-186373509 -327130969
154999046 46750274
-933523447 349415487
-437683609 140099255
864996699 -262318199
811293034 -264299324
120273173 52410685
874944410 -52048424
445049930 -803690605
-138111276 -104634331
720288580 126597671
471164416 -348777147
-356502322...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500000 tokens

Test #6:

score: -100
Wrong Answer
time: 214ms
memory: 47652kb

input:

100848 500000 500000
720352587 361776806
231853504 -933882325
960971230 -83519300
-152772415 -631132247
842871215 -666621297
857194330 -754943024
-698506963 -705416545
-3551931 -927937446
628710320 -942247987
674921043 847145884
-325629529 475694308
-339363446 686789318
236702996 654762989
420412365...

output:

Yes
No
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

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