QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217111#6679. Not Another Path Query Problem1722087564WA 7ms127996kbC++202.6kb2023-10-16 15:04:352023-10-16 15:04:35

Judging History

This is the latest submission verdict.

  • [2023-10-16 15:04:35]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 127996kb
  • [2023-10-16 15:04:35]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = long long;
const int M = 62;

struct DSU {
    int n;
    std::vector<int> fa;

    DSU(int n) {
        this->n = n;
        fa.resize(n + 1);
        std::iota(fa.begin(), fa.end(), 0);
    }

    int find(int x) {
        if (x < 1 || x > n) {
            std::cout << x << "\n";
        }
        // assert(x >= 1 && x <= n);
        return fa[x] == x ? x : fa[x] = find(fa[x]);
    }

    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        }
        fa[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

const int N = 5e5 + 10;
std::vector<DSU> dsu(M + 1, DSU(N));

signed main() {
    // std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr);

    int n, m, q;
    i64 Value;
    std::cin >> n >> m >> q >> Value;

    for (int i = 1; i <= m; i++) {
        int u, v;
        i64 w;
        std::cin >> u >> v >> w;
        // if (w == Value || !(Value & 1) && w == Value + 1) {
        //     dsu[0].merge(u, v);
        // }

        if ((w & 1) == (Value & 1) && ((w >> 1) & (Value >> 1)) == (Value >> 1)) {
            dsu[0].merge(u, v);
        }

        for (int j = 0; j < M; j++) {
            if ((w >> j & 1) && (!(Value >> j & 1)) &&
                (((w >> (j + 1)) & (Value >> (j + 1))) == (Value >> (j + 1)))) {
                dsu[j].merge(u, v);
            }

            // if ((w >> j & 1) &&
            //     (((w >> (j + 1)) & (Value >> (j + 1))) == (Value >> (j + 1)))) {
            //     dsu[j].merge(u, v);
            //     printf("MERGE %d %d %d\n", u, v, j);
            // }
            // if ((w >> j) == (Value >> j)) {
            //     dsu[j].merge(u, v);
            // }
        }
    }

    while (q--) {
        int u, v;
        std::cin >> u >> v;
        /*ans = "No";
        for (int i = M - 1; i > maxd; i--) {
            if (dsu[i].same(u, v)) {
                ans = "Yes";
                break;
            }
        }
        if (ans == "Yes") {
            std::cout << ans << "\n";
            continue;
        }*/
        std::string ans = "Yes";
        for (int i = M - 1; i >= 0; i--) {
            if (!dsu[i].same(u, v) && (Value >> i & 1)) {
                ans = "No";
                break;
            }
            if (dsu[i].same(u, v) && !(Value >> i & 1)) {
                ans = "Yes";
                break;
            }
        }
        std::cout << ans << "\n";
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 127996kb

input:

9 8 4 5
1 2 8
1 3 7
2 4 1
3 4 14
2 5 9
4 5 7
5 6 6
3 7 15
1 6
2 7
7 6
1 8

output:

No
No
No
No

result:

wrong answer expected YES, found NO [1st token]