This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int cp[N], n, Q;
int fi(int x){ return cp[x] = (cp[x] == x) ? x : fi(cp[x]); }
void uni(int u, int v){
u = fi(u), v = fi(v);
cp[v] = u;
return;
}
int main(void){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> Q;
for(int i = 1; i <= 2*n; i++) cp[i] = i;
while(Q--){
char op; int u, v; cin >> op >> u >> v;
if(op == 'A'){ //differ
uni(u, v+n);
uni(u+n, v);
} else if (op == 'R'){ //same
uni(u, v);
uni(u+n, v+n);
} else {
//cout << fi(u) << " " << fi(v) << " " << fi(u+n) << " " << fi(v+n) << "\n";
if(fi(u) == fi(v)) cout << "R\n";
else if(fi(u) == fi(v+n)) cout << "A\n";
else cout << "?\n";
}
}
return 0;
}
# | 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... |