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>
#define DEBUG 0
using namespace std;
using pii = pair <int, int>;
const int N = 1e5 + 10;
int parent[2 * N];
int root(int u) {
if(u == parent[u]) {
return u;
}
return parent[u] = root(parent[u]);
}
void Union(int u, int v) {
parent[root(u)] = root(v);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
for(int i = 1; i <= 2 * n; i++) {
parent[i] = i;
}
while(q--) {
char t;
int a, b;
cin >> t >> a >> b;
if(t == 'R') {
Union(a, b);
Union(a + n, b + n);
}
else if(t == 'A') {
Union(a, b + n);
Union(a + n, b);
}
else {
if(root(a) == root(b) && root(a) == root(b + n)) {
cout << "?\n";
}
else if(root(a) == root(b + n)) {
cout << "A\n";
}
else if(root(a) == root(b)) {
cout << "R\n";
}
else {
cout << "?\n";
}
}
if(DEBUG) {
for(int i = 1; i <= 2 * n; i++) {
cout << i << " " << root(i) << endl;
}
}
}
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... |