QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667706 | #6679. Not Another Path Query Problem | Faruk982 | WA | 20ms | 6932kb | C++23 | 1.6kb | 2024-10-23 03:28:01 | 2024-10-23 03:28:01 |
Judging History
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];
map<ll,ll>vis;
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()
{
int n,mi,j,wt,total_cost=0,u,v,m,i;
int q,V;
cin>>n>>m>>q>>V;
vector<pair<int,pair<int,int> > >edges;
for(int i=1;i<=m;i++){
int u,v,w;
cin>>u>>v>>w;
edges.push_back({w,{u,v}});
}
vector<int>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<int,int>>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: 3584kb
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: 3592kb
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
Wrong Answer
time: 20ms
memory: 6932kb
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:
No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
wrong answer expected YES, found NO [1st token]