Submission #491640

#TimeUsernameProblemLanguageResultExecution timeMemory
491640JomnoiExperimental Charges (NOI19_charges)C++17
100 / 100
27 ms2512 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...