QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142518#6679. Not Another Path Query ProblemNBestTL 1ms5620kbC++171.3kb2023-08-19 10:01:582023-08-19 10:02:01

Judging History

This is the latest submission verdict.

  • [2023-08-19 10:02:01]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 5620kb
  • [2023-08-19 10:01:58]
  • 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+m);
    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: 5500kb

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: 0
Accepted
time: 1ms
memory: 5620kb

input:

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

output:

Yes

result:

ok YES

Test #3:

score: -100
Time Limit Exceeded

input:

100 2000 50000 0
32 52 69658009083393280
26 38 868250171554967916
87 32 743903879320440454
22 15 19782587273744714
57 98 845866434191429143
42 95 1145336983294966993
67 40 1036117659380117375
46 24 265457274847122243
63 44 438254608190938148
28 23 992625102587165494
57 87 558124114385470345
6 17 535...

output:


result: