比赛 2024暑期C班集训3 评测结果 AWAAAAAAAAAAEEEEEEEE
题目名称 不是一道路径查询问题 最终得分 55
用户昵称 wzh0425 运行时间 2.002 s
代码语言 C++ 内存使用 118.11 MiB
提交时间 2024-07-03 11:12:11
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
long long n,m,q,V,f[5005][5005],b[65],c[65];
long long yu(long long x,long long y){
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    long long t=x;
    for (long long j=1;j<=61;j++){
        b[j]+=t%2;
        t/=2;
        if (t==0) break;
    }
    long long t2=y;
    for (long long i=1;i<=61;i++){
        c[i]+=t2%2;
        t2/=2;
        if (t2==0) break;
    }
    long long sum=0;
    for (long long i=1;i<=61;i++){
        if (b[i]==c[i]&&b[i]==1){
            sum+=pow(2,i-1);
        }
    }
    return sum;
}
int main(){
    freopen("Paths.in","r",stdin);
    freopen("Paths.out","w",stdout);
    scanf("%lld%lld%lld%lld",&n,&m,&q,&V);
    for (long long i=1;i<=m;i++){
        long long x,y,z;
        cin>>x>>y>>z;
        f[x][y]=z;
        f[y][x]=z;
    }
    for (long long k=1;k<=n;k++){
        for (long long i=1;i<=n;i++){
            for (long long j=1;j<=n;j++){
                f[i][j]=max(f[i][j],yu(f[i][k],f[k][j]));
            }
        }
    }
    for (long long i=1;i<=q;i++){
        long long x,y;
        cin>>x>>y;
        if (f[x][y]>=V) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}