QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#61941#3996. RacefbabicWA 5ms24380kbC++142.5kb2022-11-16 03:11:132022-11-16 03:11:16

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-16 03:11:16]
  • Judged
  • Verdict: WA
  • Time: 5ms
  • Memory: 24380kb
  • [2022-11-16 03:11:13]
  • Submitted

answer

#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m, k, q;
vector< pair<int, int> > graph[maxn];
int comp[maxn], dep[maxn];
int t[maxn];
vector< int > cyc[maxn];
vector< pair<int, int> > bas[maxn];
bool used[maxn][31];

void dfs(int x, int parr, int c) {
	dep[x] = 1 + dep[parr];
	comp[x] = c;
	for (auto iter : graph[x]) {
		int tren = iter.X;
		int val = 1 << iter.Y;
		//if (tren == parr) continue;
		used[c][iter.Y] = true;

		if (comp[tren] == -1) {
			t[tren] = t[x] ^ val;
			dfs(tren, x, c);
		} else if (dep[x] >= dep[tren] && (t[x] ^ t[tren] ^ val) != 0) 
			cyc[c].push_back(t[x] ^ t[tren] ^ val);
	}
}

int main() {
	scanf("%d%d%d%d", &n, &m, &k, &q);
	for (int i = 0; i < m; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c); c--;

		graph[a].push_back({b, c});
		graph[b].push_back({a, c});
	}

	memset(comp, -1, sizeof comp);
	memset(used, false, sizeof used);
	for (int i = 1; i <= n; i++) {
		if (comp[i] == -1) {
			dfs(i, 0, i);
			//printf("component: %d\n", i);
			//for (int tren : cyc[i]) printf("%d ", tren);
			//printf("\n");

			vector< int > bio(cyc[i].size(), -1);
			for (int j = 0; j < k; j++) {
				for (int l = 0; l < cyc[i].size(); l++) {
					if (bio[l] > -1) continue;

					int ac = cyc[i][l];
					if (ac & (1 << j)) {
						bio[l] = j;
						for (int t = 0; t < cyc[i].size(); t++) {
							if (t != l && (cyc[i][t] & (1 << j))) cyc[i][t] ^= ac;
						}
						break;
					}
				}
			}
			for (int j = 0; j < cyc[i].size(); j++) {
				if (bio[j] > -1) bas[i].push_back({cyc[i][j], bio[j]});
			}
		}
	}

	while (q--) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (comp[a] != comp[b]) {
			printf("No\n");
			continue;
		}

		int c = comp[a];
		bool flag = true;
		for (int i = 0; i < k; i++) {
			if (!used[c][i]) flag = false;
		}
		if (!flag) {
			printf("No\n");
			continue;
		}

		int val = t[a] ^ t[b];
		for (auto iter : bas[c]) {
			int tr = iter.X;
			int bit = iter.Y;
			if (val & (1 << bit)) val ^= tr;
		}

		if (val == 0) {
			printf("Yes\n");
			continue;
		}

		val = t[a] ^ t[b];
		for (auto iter : bas[c]) {
			int tr = iter.X;
			int bit = iter.Y;
			if (!(val & (1 << bit))) val ^= tr;
		}

		if (val == ((1 << k) - 1)) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 24352kb

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

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

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]