QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806696#3996. Raceucup-team2172#WA 2ms7780kbC++231.9kb2024-12-09 14:06:472024-12-09 14:06:49

Judging History

This is the latest submission verdict.

  • [2024-12-09 14:06:49]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 7780kb
  • [2024-12-09 14:06:47]
  • Submitted

answer

#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int ch = 0, f = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
const int N = 200005;
tuple<int, int, int> es[N];
vector<int> g[N];
int val[N], vis[N], fa[N], n, m, k, Q;
struct LinearBase{
    int a[30];
    inline void insert(int x){
        for(int i = 0; i < k; i++) if((1 << i) & x){
            if(!a[i]) return (void) (a[i] = x);
            else x ^= a[i];
        }
    }
    inline int find(int x){
        for(int i = 0; i < k; i++)
            if((1 << i) & x) x ^= a[i];
        return !x;
    }
} S[N];

inline int ask(int x){ return x == fa[x] ? x : fa[x] = ask(fa[x]); }

inline void dfs(int u, int pa, int sum){
    val[u] = sum, vis[u] = 1;
    for(auto ind : g[u]) if(ind != pa){
        auto [x, y, z] = es[ind];
        int v = u ^ x ^ y;
        if(vis[v]) S[ask(x)].insert(val[u] ^ val[v] ^ z);
        else dfs(v, ind, sum ^ z);
    }
}
int main(){
    read(n), read(m), read(k), read(Q);
    for(int i = 1; i <= n; i++) fa[i] = i;
    for(int i = 1, x, y, z; i <= m; i++){
        read(x), read(y), read(z);
        es[i] = {x, y, 1 << (z - 1)};
        g[x].push_back(i);
        g[y].push_back(i);
        int p = ask(x), q = ask(y);
        if(p != q) fa[p] = q;
    }
    for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i, -1, 0);
    int all = (1 << k) - 1;
    for(int i = 1, x, y; i <= Q; i++){
        read(x), read(y);
        if(ask(x) != ask(y)) puts("No");
        else{
            if(S[ask(x)].find(all ^ val[x] ^ val[y]) ||
               S[ask(x)].find(val[x] ^ val[y])
            ) puts("Yes");
            else puts("No");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7680kb

input:

7 9 3 4
1 2 1
2 3 1
3 1 2
1 4 3
5 6 2
6 7 1
6 7 3
7 7 2
5 5 1
6 7
1 4
2 4
2 5

output:

Yes
No
Yes
No

result:

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

Test #2:

score: 0
Accepted
time: 2ms
memory: 7780kb

input:

9 10 3 5
7 2 2
4 2 1
7 1 1
2 8 1
1 7 2
2 7 3
2 8 1
7 2 1
7 5 1
8 1 2
6 4
6 7
8 4
5 1
8 6

output:

No
No
Yes
Yes
No

result:

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

Test #3:

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

input:

39 30 5 999
12 22 4
11 1 1
28 13 3
35 1 4
7 17 2
20 19 4
28 7 5
15 33 5
31 38 5
13 33 4
13 35 2
16 12 5
13 33 1
21 15 3
23 32 1
19 16 3
3 22 3
11 14 2
31 26 5
32 17 5
34 17 3
31 26 2
10 37 1
1 3 1
30 12 4
1 35 3
6 1 2
25 15 2
39 23 5
10 5 3
24 34
32 27
4 13
37 28
31 36
12 11
24 6
22 32
7 17
1 15
22 ...

output:

No
No
No
No
No
Yes
No
Yes
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
No
Yes
No
Yes
Yes
No
No
No
No
No
Yes
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
N...

result:

wrong answer expected NO, found YES [496th token]