QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61824#3996. RaceblaWA 5ms16532kbC++141.9kb2022-11-15 03:44:012022-11-15 03:44:02

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.
  • [2022-11-15 03:44:02]
  • Judged
  • Verdict: WA
  • Time: 5ms
  • Memory: 16532kb
  • [2022-11-15 03:44:01]
  • Submitted

answer

#include <bits/stdc++.h> 

#define X first
#define Y second
#define pb push_back 

using namespace std;

typedef pair<int, int> pii;

const int LOG = 31;
const int N = 2e5 + 10;

int n, m, q, k, comp[N], base[LOG], mask[N];
int xr[N], bio[N], bioe[N], rep[N], ans[N];

vector<int> space;
vector<pii> g[N];
vector<pair<int, pii>> qs[N];

bool add(int x, bool flag){
	while(x && base[__lg(x)] != -1){
		x ^= space[base[__lg(x)]];
	}
	if(!flag){
	//	printf("x = %d\n", x);
		if(x) base[__lg(x)] = space.size();
		space.pb(x);
		return 0;
	}
	return x == 0;
}

void dfs(int u){
	bio[u] = true;
	for(pii e : g[u]){
		int v = e.X, c = mask[e.Y];
		if(bio[v]){
			if(!bioe[e.Y]){
				bioe[e.Y] = true;
				add(xr[u] ^ xr[v] ^ c, 0);
			}
			continue;				
		}
		bioe[e.Y] = true; 
		xr[v] = xr[u] ^ c;
		//printf("xr[%d] = %d\n", v, xr[v]);
		dfs(v);
	}
}

void rec(int u, int c){
	bio[u] = true;
	comp[u] = c;
	for(pii e : g[u]){
		if(!bio[e.X]) rec(e.X, c);
	}
}

int ne(int x){
	for(int i = 0; i < k; i++){
		x ^= 1 << i;
	}
	return x;
}

int main(){
	scanf("%d%d%d%d", &n, &m, &k, &q);
	for(int i = 0; i < m; i++){
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		mask[i] = 1 << (c - 1);
		g[u].pb({v, i});
		g[v].pb({u, i});
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(!bio[i]){
			rec(i, cnt);
			rep[cnt] = i;
			cnt++;
		}
	}
	memset(bio, 0, sizeof(bio));
	for(int i = 0; i < q; i++){
		int s, t;
		scanf("%d%d", &s, &t);
		if(comp[s] == comp[t]) qs[comp[s]].pb({i, {s, t}});
	}
	for(int i = 0; i < cnt; i++){
		memset(base, -1, sizeof(base));
		space.clear();
		dfs(rep[i]);
		for(pair<int, pii> p : qs[i]) ans[p.X] = add(xr[p.Y.X] ^ xr[p.Y.Y], 1) | add(ne(xr[p.Y.X] ^ xr[p.Y.Y]), 1);
	}
	for(int i = 0; i < q; i++){
		if(ans[i] == 0) printf("No\n");
		else printf("Yes\n");
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 16532kb

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: 5ms
memory: 15944kb

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: 15396kb

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
Yes
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
Yes
No
No
No
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
N...

result:

wrong answer expected NO, found YES [496th token]