QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124510#6679. Not Another Path Query ProblemHOLICWA 1ms13732kbC++141.1kb2023-07-15 01:21:372023-07-15 01:21:39

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-15 01:21:39]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 13732kb
  • [2023-07-15 01:21:37]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1009;
const int M = 5e5 + 1009;
#define endl "\n"
int n, m, q, x[M], y[M], a[M], b[M], ans[M], fa[N];
long long v, z[M];
int find(int x) {
    if(fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
void check(long long V) {
    for(int i = 1; i <= n; i ++) fa[i] = i;
    for(int i = 1; i <= m; i ++) {
        if((z[i] & V) == V) fa[find(x[i])] = find(y[i]);
    }
    for(int i = 1; i <= q; i ++) {
        if(ans[i]) continue;
        if(find(a[i]) == find(b[i])) ans[i] = 1;
    }
}
void work() {
    cin >> n >> m >> q >> v;
    for(int i = 1; i <= m; i ++) {
        cin >> x[i] >> y[i] >> z[i];
    }
    for(int i = 1; i <= q; i ++) cin >> a[i] >> b[i];
    long long V = 0;
    for(int i = 59; i >= 0; i --) {
        if((z[i] >> i) & 1) V |= (1ll << i);
        else check(V | (1ll << i));
    }
    check(V);
    for(int i = 1; i <= q; i ++)
        cout << (ans[i] ? "Yes" : "No") << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int Case = 1;
    while(Case --) work();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 13640kb

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: -100
Wrong Answer
time: 1ms
memory: 13732kb

input:

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

output:

No

result:

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