QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77434#3996. RacechenshiWA 2ms7532kbC++1.2kb2023-02-14 17:12:382023-02-14 17:12:42

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-14 17:12:42]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 7532kb
  • [2023-02-14 17:12:38]
  • Submitted

answer

#include<cstdio>
using namespace std;
const int o=2e5+10;
struct foo{
	int z[30];
	inline void ins(int x){
		for(int i=30;i--;) if((x>>i)&1)
			if(!z[i]){z[i]=x;break;}
			else x^=z[i];
	}
	inline bool chk(int x){
		for(int i=30;i--;) if((x>>i)&1)
			if(!z[i]) return false;
			else x^=z[i];
		return true;
	}
}bar[o];
int n,m,K,q,fa[o],h[o],cnt,w[o],S[o];bool vis[o];
struct Edge{int v,p,w;}e[o*2];
inline void ad(int U,int V,int W){e[++cnt].v=V;e[cnt].p=h[U];e[h[U]=cnt].w=W;}
int fr(int x){return fa[x]==x?x:fa[x]=fr(fa[x]);}
void dfs(int nw){
	vis[nw]=1;
	for(int i=h[nw];i;S[fr(nw)]|=e[i].w,i=e[i].p)
		if(!vis[e[i].v]) w[e[i].v]=w[nw]^e[i].w,dfs(e[i].v);
		else bar[fr(nw)].ins(w[nw]^w[e[i].v]^e[i].w);
}
int main(){
	scanf("%d%d%d%d",&n,&m,&K,&q);
	for(int i=1;i<=n;++i) fa[i]=i;
	for(int i=1,u,v,w;i<=m;++i) scanf("%d%d%d",&u,&v,&w),w=(1<<(w-1)),ad(u,v,w),ad(v,u,w),fa[fr(u)]=fr(v);
	for(int i=1;i<=n;++i) if(fa[i]==i) dfs(i);
	for(int x,y,t;q--;){
		scanf("%d%d",&x,&y);
		if((t=fr(x))^fr(y)) printf("No\n");
		else if(S[t]^((1<<K)-1)) printf("No\n");
		else if(bar[t].chk(w[x]^w[y])||bar[t].chk(w[x]^w[y]^((1<<K)-1))) 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: 7532kb

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

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

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]