#include <bits/stdc++.h>
using ll = long long;
class djf{
public:
ll n;
std::vector<ll> par;
djf(ll n) : n(n) , par(n+1) {
for(int i = 1 ; i<=n ; i++){
par[i] = i;
}
};
ll root(ll x){
if(par[x] ==x){
return x;
}
return root(par[x]);
}
void merge(ll u , ll v){
u = root(u);
v = root(v);
if(u == v) return;
par[v] = u;
}
};
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n , q;
std::cin >> n >> q;
djf s(2*n);
while(q--){
char c;
ll a , b;
std::cin >> c >> a >> b;
if(c == 'A'){
s.merge(a, b+n);
s.merge(a+n , b);
}
else if(c == 'R'){
s.merge(a , b);
s.merge(a+n , b+n);
}
else{
if(s.root(a) == s.root(b)){
std::cout << "R\n";
}
else if(s.root(a) == s.root(b+n)){
std::cout << "A\n";
}
else{
std::cout << "?\n";
}
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |