#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 1e5 + 10;
ll par[maxn];
ll N, Q, A, B;
char T;
ll find_par(ll u)
{
if (u == par[u])
{
return u;
}
par[u] = find_par(par[u]);
return par[u];
}
void merge(ll x, ll y)
{
ll rootx = find_par(x);
ll rooty = find_par(y);
if (rootx == rooty)
{
return;
}
par[rootx] = rooty;
}
signed main()
{
for (ll i = 1; i < maxn; i++)
{
par[i] = i;
}
cin >> N >> Q;
for (ll i = 1; i <= Q; i++)
{
cin >> T >> A >> B;
if (T == 'R')
{
merge(A, B);
}
else if (T == 'A')
{
merge(A, B + N);
merge(B, A + N);
}
else
{
if (find_par(A) == find_par(B))
{
cout << "R" << "\n";
}
else if (find_par(A) == find_par(B + N))
{
cout << "A" << "\n";
}
else
{
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... |