QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142641 | #3996. Race | chenxinyang2006 | WA | 2ms | 5884kb | C++14 | 2.5kb | 2023-08-19 16:10:44 | 2023-08-19 16:10:45 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,m,k,q;
int cnt = 1;
int head[200005];
struct eg{
int to,w,nxt;
}edge[400005];
void make(int u,int v,int w){
edge[++cnt].to = v;
edge[cnt].w = w;
edge[cnt].nxt = head[u];
head[u] = cnt;
}
int ww[200005][32];
void insert(int id,int val){
per(i,k - 1,0){
if(((val >> i) & 1) == 0) continue;
if(!ww[id][i]){
ww[id][i] = val;
return;
}
val ^= ww[id][i];
}
}
int qry(int id,int val){
per(i,k - 1,0) chkmin(val,val ^ ww[id][i]);
return val;
}
int getval(int c){
c = (1 << (c - 1));
if(c == (1 << (k - 1))) c--;
return c;
}
int vis[200005],dep[200005],occ[200005][35];
void dfs(int u,int I,int c){
vis[u] = c;
for(int i = head[u];i;i = edge[i].nxt){
int v = edge[i].to;
if(i == (I ^ 1)) continue;
occ[c][edge[i].w] = 1;
if(!vis[v]){
dep[v] = dep[u] ^ getval(edge[i].w);
// printf("%d -> %d %d\n",u,v,dep[v]);
dfs(v,i,c);
}else{
// printf("simple cir %d\n",dep[u] ^ dep[v] ^ edge[i].w);
insert(c,dep[u] ^ dep[v] ^ getval(edge[i].w));
}
}
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d%d%d%d",&n,&m,&k,&q);
rep(i,1,m){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
make(u,v,w);make(v,u,w);
}
rep(u,1,n){
if(vis[u]) continue;
dfs(u,0,u);
}
rep(i,1,q){
int u,v;
scanf("%d%d",&u,&v);
if(vis[u] != vis[v]){
printf("No\n");
continue;
}
int flg = 1;
rep(j,1,k) flg &= occ[vis[u]][j];
if(!flg){
printf("No\n");
continue;
}
if(!qry(vis[u],dep[u] ^ dep[v])) printf("Yes\n");
else printf("No\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5620kb
input:
7 9 3 4 1 2 1 2 3 1 3 1 2 1 4 3 5 6 2 6 7 1 6 7 3 7 7 2 5 5 1 6 7 1 4 2 4 2 5
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: 5748kb
input:
9 10 3 5 7 2 2 4 2 1 7 1 1 2 8 1 1 7 2 2 7 3 2 8 1 7 2 1 7 5 1 8 1 2 6 4 6 7 8 4 5 1 8 6
output:
No No Yes Yes No
result:
ok 5 token(s): yes count is 2, no count is 3
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 5884kb
input:
39 30 5 999 12 22 4 11 1 1 28 13 3 35 1 4 7 17 2 20 19 4 28 7 5 15 33 5 31 38 5 13 33 4 13 35 2 16 12 5 13 33 1 21 15 3 23 32 1 19 16 3 3 22 3 11 14 2 31 26 5 32 17 5 34 17 3 31 26 2 10 37 1 1 3 1 30 12 4 1 35 3 6 1 2 25 15 2 39 23 5 10 5 3 24 34 32 27 4 13 37 28 31 36 12 11 24 6 22 32 7 17 1 15 22 ...
output:
No No No No No Yes No Yes No No No No Yes No No No Yes No No No No No No No No No No Yes No Yes No No Yes Yes No No No Yes No No No No No Yes No Yes Yes No No No No No Yes No Yes 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 N...
result:
wrong answer expected YES, found NO [32nd token]