比赛 2024暑期C班集训3 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 不是一道路径查询问题 最终得分 100
用户昵称 darkMoon 运行时间 2.835 s
代码语言 C++ 内存使用 12.98 MiB
提交时间 2024-07-03 10:44:12
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
ifstream fin("Paths.in");
ofstream fout("Paths.out");
auto mread = [](){
    int x;
    fin >> x;
    return x;
};
const int N = 5e5 + 5;
int n = mread(), m = mread(), q = mread(), v = mread();
struct node{
    int u, v, w;
}s[N];
struct Node{
    int u, v, ans;
}a[N];
int fa[N];
int findfa(int x){
    if(fa[x] == x)
    return x;
    return fa[x] = findfa(fa[x]);
}
void add(int x, int y){
    int a = findfa(x), b = findfa(y);
    if(a != b){
        fa[a] = b;
    }
    return;
}
void check(int x){
//    cout << (bitset<62>)x << "\n";
    for(int i = 1; i <= n; i ++)
    fa[i] = i;
    for(int i = 1; i <= m; i ++){
        if((s[i].w | x) == s[i].w){
            add(s[i].u, s[i].v);
        }
    }
    for(int i = 1; i <= q; i ++){
        if(findfa(a[i].u) == findfa(a[i].v)){
            a[i].ans = 1;
        }
    }
} 
signed main(){
    for(int i = 1; i <= m; i ++){
        s[i].u = mread();
        s[i].v = mread();
        s[i].w = mread(); 
    }
    for(int i = 1; i <= q; i ++){
        a[i].u = mread(), a[i].v = mread();
    }
    for(int i = 0; i <= 61; i ++){
        if((v >> i) & 1){
            check(v);
        }
        else{
            int x = v;
            x |= (1ll << i);
            x &= ~((1ll << i) - 1);
            check(x);
        }
    }
    for(int i = 1; i <= q; i ++){
        if(a[i].ans){
            fout << "Yes\n";
        }
        else{
            fout << "No\n";
        }
    }
}