QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#180697#6679. Not Another Path Query Problemsupepapupu#TL 0ms3720kbC++171.7kb2023-09-16 09:56:292023-09-16 09:56:29

Judging History

This is the latest submission verdict.

  • [2023-09-16 09:56:29]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3720kb
  • [2023-09-16 09:56:29]
  • Submitted

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> plll;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;

inline int read() {
    int f = 1, k = 0;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        k = k * 10 + c - '0';
        c = getchar();
    }
    return f * k;
}

int n, m, Q, V;
int fa[N][70];
vector<plll> e;

int find(int x, int o) {
    return fa[x][o] == x ? x : fa[x][o] = find(fa[x][o], o);
}

void build(ll v, int o) {
    for (int i = 1; i <= n; ++i) fa[i][o] = i;
    for (auto[a, b, w]: e) {
        if ((w & v) == v) {
            // cout << a << ' ' << b << el;
            fa[find(a, o)][o] = find(b, o);
        }
    }
    // cout << o << "----\n";
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> Q >> V;
    while (m--) {
        ll u, v, w;
        cin >> u >> v >> w;
        e.push_back({u, v, w});
    }
    for (ll i = V, j = 0; i < 1ll << 60; i += i & -i, ++j) {
        build(i, j);
    }
    while (Q--) {
        int u, v;
        cin >> u >> v;
        bool f = 0;
        for (ll i = V, j = 0; i < 1ll << 60; i += i & -i, ++j) {
            if (find(u, j) == find(v, j)) {
                // cout << u << ' ' << v << ' ' << V << el;
                // cout << find(u, j) << ' ' << find(v, j) << el;
                f = 1; break;
            }
        }
        cout << (f ? "Yes\n" : "No\n");
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

Yes
No
Yes
No

result:

ok 4 token(s): yes count is 2, no count is 2

Test #2:

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

input:

3 4 1 4
1 2 3
1 2 5
2 3 2
2 3 6
1 3

output:

Yes

result:

ok YES

Test #3:

score: -100
Time Limit Exceeded

input:

100 2000 50000 0
32 52 69658009083393280
26 38 868250171554967916
87 32 743903879320440454
22 15 19782587273744714
57 98 845866434191429143
42 95 1145336983294966993
67 40 1036117659380117375
46 24 265457274847122243
63 44 438254608190938148
28 23 992625102587165494
57 87 558124114385470345
6 17 535...

output:


result: