# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491638 | Jomnoi | Experimental Charges (NOI19_charges) | C++17 | 29 ms | 2916 KiB |
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[N];
int dist[N];
int root(int u) {
if(u == parent[u]) {
return u;
}
int tmp = parent[u];
parent[u] = root(parent[u]);
dist[u] = (dist[u] + dist[tmp]) % 2;
return parent[u];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i++) {
parent[i] = i;
dist[i] = 0;
}
while(q--) {
char t;
int a, b;
cin >> t >> a >> b;
if(t == 'R' || t == 'A') {
int d = (t == 'A');
int u = root(a), v = root(b);
if(u == v) {
continue;
}
parent[u] = v;
dist[u] = (dist[v] + 1) % 2;
}
else {
if(root(a) != root(b)) {
cout << "?\n";
continue;
}
cout << (abs(dist[a] - dist[b]) % 2 ? 'R' : 'A') << '\n';
}
}
return 0;
}
Compilation message (stderr)
# | 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... |