# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491638 | 2021-12-03T15:50:10 Z | Jomnoi | Experimental Charges (NOI19_charges) | C++17 | 29 ms | 2916 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Incorrect | 0 ms | 204 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 29 ms | 1964 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 2480 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 2916 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Incorrect | 0 ms | 204 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Incorrect | 0 ms | 204 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |