#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 2e5+5 , INF = 1e18 , MOD = 1e9+7;
vector<ll> par(N);
void make_set(ll n){
for(ll i = 1; i <= n; i++){
par[i] = i;
}
}
ll find(ll x){
if(x == par[x]) return x;
return par[x] = find(par[x]);
}
void unite(ll a , ll b){
a = find(a);
b = find(b);
if(a == b) return;
par[b] = a;
}
void solve(){
ll n,q;
cin >> n >> q;
make_set(2*n);
while(q--){
char x;
ll a,b;
cin >> x >> a >> b;
if(x == 'R'){
unite(a,b);
unite(a+n,b+n);
}
else if(x == 'A'){
unite(a+n,b);
unite(a,b+n);
}
else{
if(find(a) == find(b) || find(a+n) == find(b+n)){
cout << "R\n";
}
else if(find(a+n) == find(b) || find(a) == find(b+n)){
cout << "A\n";
}
else cout << "?\n";
}
}
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2888 KB |
Output is correct |
2 |
Correct |
19 ms |
2900 KB |
Output is correct |
3 |
Correct |
20 ms |
2852 KB |
Output is correct |
4 |
Correct |
21 ms |
3044 KB |
Output is correct |
5 |
Correct |
19 ms |
2788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3164 KB |
Output is correct |
2 |
Correct |
23 ms |
3172 KB |
Output is correct |
3 |
Correct |
22 ms |
3188 KB |
Output is correct |
4 |
Correct |
26 ms |
3276 KB |
Output is correct |
5 |
Correct |
28 ms |
3196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3156 KB |
Output is correct |
2 |
Correct |
21 ms |
3356 KB |
Output is correct |
3 |
Correct |
23 ms |
3156 KB |
Output is correct |
4 |
Correct |
27 ms |
3188 KB |
Output is correct |
5 |
Correct |
28 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
1908 KB |
Output is correct |
10 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
20 ms |
2888 KB |
Output is correct |
7 |
Correct |
19 ms |
2900 KB |
Output is correct |
8 |
Correct |
20 ms |
2852 KB |
Output is correct |
9 |
Correct |
21 ms |
3044 KB |
Output is correct |
10 |
Correct |
19 ms |
2788 KB |
Output is correct |
11 |
Correct |
19 ms |
3164 KB |
Output is correct |
12 |
Correct |
23 ms |
3172 KB |
Output is correct |
13 |
Correct |
22 ms |
3188 KB |
Output is correct |
14 |
Correct |
26 ms |
3276 KB |
Output is correct |
15 |
Correct |
28 ms |
3196 KB |
Output is correct |
16 |
Correct |
20 ms |
3156 KB |
Output is correct |
17 |
Correct |
21 ms |
3356 KB |
Output is correct |
18 |
Correct |
23 ms |
3156 KB |
Output is correct |
19 |
Correct |
27 ms |
3188 KB |
Output is correct |
20 |
Correct |
28 ms |
3156 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
2 ms |
1908 KB |
Output is correct |
25 |
Correct |
2 ms |
1876 KB |
Output is correct |
26 |
Correct |
23 ms |
3152 KB |
Output is correct |
27 |
Correct |
25 ms |
3192 KB |
Output is correct |
28 |
Correct |
24 ms |
3156 KB |
Output is correct |
29 |
Correct |
25 ms |
3148 KB |
Output is correct |
30 |
Correct |
25 ms |
3148 KB |
Output is correct |