QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142514#6679. Not Another Path Query ProblemNBestWA 2ms9600kbC++171.3kb2023-08-19 09:56:222023-08-19 09:56:26

Judging History

This is the latest submission verdict.

  • [2023-08-19 09:56:26]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 9600kb
  • [2023-08-19 09:56:22]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
    return x*f;
}
struct edge{
    int u,v;
    ll w;
    inline bool operator<(const edge &o)const{
        return w>o.w;
    }
}a[500005];
int fa[100005],n,m,q;
ll V,maxw;
PII qr[500005];
bool ans[500005];
inline int find(int x){
    if(x==fa[x])return x;
    return fa[x]=find(fa[x]);
}
void work(ll o){
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=m;i++){
        if(a[i].w<o)break;
        if((a[i].w&o)==o)//注意:&运算的优先级小于==
            fa[find(a[i].u)]=find(a[i].v);
    }
    for(int i=1;i<=q;i++){
        if(find(qr[i].first)==find(qr[i].second))
            ans[i]=1;
    }
}
int main(){
    n=read(),m=read(),q=read(),V=read();
    for(int i=1;i<=m;i++){
        int u=read(),v=read();
        ll w=read();
        a[i]={u,v,w};
        maxw=max(maxw,w);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=q;i++){
        int u=read(),v=read();
        qr[i]={u,v};
    }
    for(ll p=V;p<=maxw;p+=(p&-p)){
        work(p);
    }
    for(int i=1;i<=q;i++){
        puts(ans[i]?"Yes":"No");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 9600kb

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]