#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 2e5+10;
int dsu[mxn],sz[mxn];
int n,q;
int root(int k){
return k == dsu[k]?k:dsu[k] = root(dsu[k]);
}
inline void onion(int a,int b){
a = root(a),b = root(b);
if(a == b)return;
if(sz[a]<sz[b])swap(a,b);
dsu[b] = a;
sz[a] += sz[b];
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>q;
for(int i = 1;i<=n*2;i++)dsu[i] = i,sz[i] = 1;
while(q--){
char c;int a,b;
cin>>c>>a>>b;
if(c == 'Q'){
if(root(a) == root(b))cout<<"R\n";
else if(root(a) == root(b+n))cout<<"A\n";
else cout<<"?\n";
}
else if(c == 'R'){
onion(a,b);
onion(a+n,b+n);
}
else{
onion(a,b+n);
onion(a+n,b);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2908 KB |
Output is correct |
2 |
Correct |
14 ms |
2692 KB |
Output is correct |
3 |
Correct |
16 ms |
2792 KB |
Output is correct |
4 |
Correct |
15 ms |
2828 KB |
Output is correct |
5 |
Correct |
18 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3416 KB |
Output is correct |
2 |
Correct |
15 ms |
3160 KB |
Output is correct |
3 |
Correct |
17 ms |
3160 KB |
Output is correct |
4 |
Correct |
18 ms |
3164 KB |
Output is correct |
5 |
Correct |
18 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3164 KB |
Output is correct |
2 |
Correct |
16 ms |
3164 KB |
Output is correct |
3 |
Correct |
17 ms |
3052 KB |
Output is correct |
4 |
Correct |
18 ms |
3376 KB |
Output is correct |
5 |
Correct |
17 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
2908 KB |
Output is correct |
7 |
Correct |
14 ms |
2692 KB |
Output is correct |
8 |
Correct |
16 ms |
2792 KB |
Output is correct |
9 |
Correct |
15 ms |
2828 KB |
Output is correct |
10 |
Correct |
18 ms |
2904 KB |
Output is correct |
11 |
Correct |
15 ms |
3416 KB |
Output is correct |
12 |
Correct |
15 ms |
3160 KB |
Output is correct |
13 |
Correct |
17 ms |
3160 KB |
Output is correct |
14 |
Correct |
18 ms |
3164 KB |
Output is correct |
15 |
Correct |
18 ms |
3420 KB |
Output is correct |
16 |
Correct |
18 ms |
3164 KB |
Output is correct |
17 |
Correct |
16 ms |
3164 KB |
Output is correct |
18 |
Correct |
17 ms |
3052 KB |
Output is correct |
19 |
Correct |
18 ms |
3376 KB |
Output is correct |
20 |
Correct |
17 ms |
3164 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
15 ms |
3164 KB |
Output is correct |
27 |
Correct |
16 ms |
3160 KB |
Output is correct |
28 |
Correct |
17 ms |
3164 KB |
Output is correct |
29 |
Correct |
16 ms |
3164 KB |
Output is correct |
30 |
Correct |
17 ms |
3164 KB |
Output is correct |