QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667710#6679. Not Another Path Query ProblemFaruk982RE 0ms3808kbC++231.6kb2024-10-23 03:33:502024-10-23 03:33:51

Judging History

This is the latest submission verdict.

  • [2024-10-23 03:33:51]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3808kb
  • [2024-10-23 03:33:50]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define SetBit(x,k)(x|=(1ll<<k))
#define ClearBit(x,k)(x&=~(1ll<<k))
#define CheckBit(x,k)((x>>k)&1)
#define CC(x) cout<<"Case "<<++x<<": ";
//const int N = 1e6 + 10;
const int modulo = 10000007;
const int N=1e5+10;
int parent[N],sz[N];

void make(int v)
{
  parent[v]=v;
  sz[v]=1;
}
int find(int v)
{
  if(parent[v]==v)return parent[v];
  else return parent[v]=find(parent[v]);
}
void Union(int a,int b)
{
  a=find(a);
  b=find(b);
  if(a!=b)
  {
    if(sz[a]<sz[b])
    {
      swap(a,b);
     
    }
     parent[b]=a;
      sz[a]+=sz[b];
  }
}
int main()
{
  ll n,mi,j,wt,total_cost=0,u,v,m,i;
  ll q,V;
  cin>>n>>m>>q>>V;
  ll vis[n+1]={0};
  vector<pair<ll,pair<ll,ll> > >edges;
  for(int i=1;i<=m;i++){
   ll u,v,w;
   cin>>u>>v>>w;
   edges.push_back({w,{u,v}});
  }
  vector<ll>need;
  need.push_back(V);
 ll ans=0;
 for(ll i=63;i>=0;i--){
    if(CheckBit(V,i)){
      SetBit(ans,i);
    }
    else{
      SetBit(ans,i);
      need.push_back(ans);
      ClearBit(ans,i);
    }
 }
 vector<pair<ll,ll>>query;
//vis.clear();
while (q--)
{
 ll u,v;
 cin>>u>>v;
 query.push_back({u,v});
}
for(auto x:need){
  for(ll i=1;i<=n;i++)make(i);
  for(auto y:edges){
    if((y.first&x)>=V)Union(y.second.first,y.second.second);
  }
  for(ll i=0;i<query.size();i++){
    if(find(query[i].first)==find(query[i].second))vis[i]=1;
  }
}
for(ll i=0;i<query.size();i++){
  if(vis[i])YES
  else NO
}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 3808kb

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
Runtime Error

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: