Submission #491638

#TimeUsernameProblemLanguageResultExecution timeMemory
491638JomnoiExperimental Charges (NOI19_charges)C++17
0 / 100
29 ms2916 KiB
#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)

charges.cpp: In function 'int main()':
charges.cpp:34:17: warning: unused variable 'd' [-Wunused-variable]
   34 |             int d = (t == 'A');
      |                 ^
#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...