#include "bits/stdc++.h"
using namespace std;
#define int long long
const int w = 1000050;
int n, m;
char c;
vector<int> parent((int) 1e7), siz((int) 1e7, 1);
int findpar(int x) {
if(x == parent[x]) return x;
return parent[x] = findpar(parent[x]);
}
void unite(int x, int y) {
x = findpar(x);
y = findpar(y);
if(x == y) return;
if(siz[y] > siz[x]) swap(x, y);
parent[y] = x;
siz[x] += siz[y];
}
signed main() {
cin >> n >> m;
for(int i = 0; i < (int) 1e7; ++i) parent[i] = i;
int x, y;
while(m--) {
cin >> c; cin >> x >> y;
if(c == 'A') {
unite(x, y + w);
unite(x + w, y);
} else if(c == 'R') {
unite(x, y);
unite(x + w, y + w);
} else {
int p, q, r;
p = findpar(x);
q = findpar(y);
r = findpar(x + w);
//s = findpar(y + w);
//if(p == q && p == s) cout << "?";
if (p == q) cout << "R";
else if (q == r) cout << "A";
else cout << "?";
cout << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
156848 KB |
Output is correct |
2 |
Correct |
78 ms |
156804 KB |
Output is correct |
3 |
Correct |
84 ms |
156748 KB |
Output is correct |
4 |
Correct |
76 ms |
156760 KB |
Output is correct |
5 |
Correct |
84 ms |
156832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
156868 KB |
Output is correct |
2 |
Correct |
169 ms |
156880 KB |
Output is correct |
3 |
Correct |
238 ms |
156992 KB |
Output is correct |
4 |
Correct |
193 ms |
156920 KB |
Output is correct |
5 |
Correct |
157 ms |
156856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
211 ms |
156916 KB |
Output is correct |
2 |
Correct |
215 ms |
156920 KB |
Output is correct |
3 |
Correct |
197 ms |
156912 KB |
Output is correct |
4 |
Correct |
172 ms |
156916 KB |
Output is correct |
5 |
Correct |
183 ms |
156944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
156852 KB |
Output is correct |
2 |
Correct |
197 ms |
156900 KB |
Output is correct |
3 |
Correct |
163 ms |
156904 KB |
Output is correct |
4 |
Correct |
167 ms |
156960 KB |
Output is correct |
5 |
Correct |
160 ms |
156844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
156848 KB |
Output is correct |
2 |
Correct |
78 ms |
156804 KB |
Output is correct |
3 |
Correct |
84 ms |
156748 KB |
Output is correct |
4 |
Correct |
76 ms |
156760 KB |
Output is correct |
5 |
Correct |
84 ms |
156832 KB |
Output is correct |
6 |
Correct |
73 ms |
156768 KB |
Output is correct |
7 |
Correct |
72 ms |
156900 KB |
Output is correct |
8 |
Correct |
72 ms |
156856 KB |
Output is correct |
9 |
Correct |
77 ms |
156744 KB |
Output is correct |
10 |
Correct |
72 ms |
156848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
156848 KB |
Output is correct |
2 |
Correct |
78 ms |
156804 KB |
Output is correct |
3 |
Correct |
84 ms |
156748 KB |
Output is correct |
4 |
Correct |
76 ms |
156760 KB |
Output is correct |
5 |
Correct |
84 ms |
156832 KB |
Output is correct |
6 |
Correct |
177 ms |
156868 KB |
Output is correct |
7 |
Correct |
169 ms |
156880 KB |
Output is correct |
8 |
Correct |
238 ms |
156992 KB |
Output is correct |
9 |
Correct |
193 ms |
156920 KB |
Output is correct |
10 |
Correct |
157 ms |
156856 KB |
Output is correct |
11 |
Correct |
211 ms |
156916 KB |
Output is correct |
12 |
Correct |
215 ms |
156920 KB |
Output is correct |
13 |
Correct |
197 ms |
156912 KB |
Output is correct |
14 |
Correct |
172 ms |
156916 KB |
Output is correct |
15 |
Correct |
183 ms |
156944 KB |
Output is correct |
16 |
Correct |
179 ms |
156852 KB |
Output is correct |
17 |
Correct |
197 ms |
156900 KB |
Output is correct |
18 |
Correct |
163 ms |
156904 KB |
Output is correct |
19 |
Correct |
167 ms |
156960 KB |
Output is correct |
20 |
Correct |
160 ms |
156844 KB |
Output is correct |
21 |
Correct |
73 ms |
156768 KB |
Output is correct |
22 |
Correct |
72 ms |
156900 KB |
Output is correct |
23 |
Correct |
72 ms |
156856 KB |
Output is correct |
24 |
Correct |
77 ms |
156744 KB |
Output is correct |
25 |
Correct |
72 ms |
156848 KB |
Output is correct |
26 |
Correct |
200 ms |
157148 KB |
Output is correct |
27 |
Correct |
196 ms |
157020 KB |
Output is correct |
28 |
Correct |
161 ms |
156876 KB |
Output is correct |
29 |
Correct |
163 ms |
156900 KB |
Output is correct |
30 |
Correct |
163 ms |
156940 KB |
Output is correct |