Submission #676479

# Submission time Handle Problem Language Result Execution time Memory
676479 2022-12-31T03:35:30 Z penguin133 Experimental Charges (NOI19_charges) C++17
100 / 100
39 ms 8524 KB
#include <bits/stdc++.h>
using namespace std;
int p[100005], C[100005];
vector<int>v[100005];
int getr(int x){
	if(p[x] == x)return x;
	else return p[x] = getr(p[x]);
}
void merge(int a, int b, int c){
	int pa = a, pb= b;
	a = getr(a); b = getr(b);
	if(a != b){
		if(v[a].size() > v[b].size()){
			p[b] = a;
			for(auto i : v[b])v[a].push_back(i);
			if(c != (C[pa] ^ C[pb]))for(auto i : v[b])C[i] = 1 - C[i];
		}
		else{
			p[a] = b;
			for(auto i : v[a])v[b].push_back(i);
			if(c != (C[pa] ^ C[pb]))for(auto i : v[a])C[i] = 1 - C[i];
		}
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int n,q;
	cin >> n >> q;
	for(int i=1;i<=n;i++)C[i] = 1, p[i] = i, v[i].push_back(i);
	while(q--){
		char a;
		int b,c;
		cin >> a >> b >> c;
		if(a == 'R')merge(b,c,0);
		else if(a == 'A')merge(b,c,1);
		else{
			if(getr(b) != getr(c))cout << "?\n";
			else cout << (((C[b] ^ C[c]) == 1) ? "A\n" : "R\n");
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 7600 KB Output is correct
2 Correct 26 ms 7668 KB Output is correct
3 Correct 27 ms 7636 KB Output is correct
4 Correct 29 ms 7632 KB Output is correct
5 Correct 34 ms 7624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 8204 KB Output is correct
2 Correct 26 ms 8204 KB Output is correct
3 Correct 36 ms 8168 KB Output is correct
4 Correct 38 ms 8396 KB Output is correct
5 Correct 34 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 8032 KB Output is correct
2 Correct 29 ms 7900 KB Output is correct
3 Correct 39 ms 7944 KB Output is correct
4 Correct 36 ms 8300 KB Output is correct
5 Correct 35 ms 8264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2684 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2672 KB Output is correct
10 Correct 2 ms 2692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 25 ms 7600 KB Output is correct
7 Correct 26 ms 7668 KB Output is correct
8 Correct 27 ms 7636 KB Output is correct
9 Correct 29 ms 7632 KB Output is correct
10 Correct 34 ms 7624 KB Output is correct
11 Correct 27 ms 8204 KB Output is correct
12 Correct 26 ms 8204 KB Output is correct
13 Correct 36 ms 8168 KB Output is correct
14 Correct 38 ms 8396 KB Output is correct
15 Correct 34 ms 8524 KB Output is correct
16 Correct 27 ms 8032 KB Output is correct
17 Correct 29 ms 7900 KB Output is correct
18 Correct 39 ms 7944 KB Output is correct
19 Correct 36 ms 8300 KB Output is correct
20 Correct 35 ms 8264 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2684 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2672 KB Output is correct
25 Correct 2 ms 2692 KB Output is correct
26 Correct 25 ms 8068 KB Output is correct
27 Correct 28 ms 8140 KB Output is correct
28 Correct 35 ms 8012 KB Output is correct
29 Correct 32 ms 8136 KB Output is correct
30 Correct 32 ms 8152 KB Output is correct