Submission #374485

#TimeUsernameProblemLanguageResultExecution timeMemory
374485vishesh312Experimental Charges (NOI19_charges)C++17
100 / 100
38 ms3308 KiB
#include "bits/stdc++.h" using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; */ #define all(x) begin(x), end(x) #define sz(x) (int)x.size() using ll = long long; const int mod = 1e9+7; struct UFDS { vector<int> siz, link; UFDS(int n) { siz.resize(n, 1); link.resize(n); for (int i = 0; i < n; ++i) link[i] = i; } int find(int x) { while (x != link[x]) x = link[x]; return x; } bool same(int a, int b) { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (siz[a] < siz[b]) swap(a, b); siz[a] += siz[b]; link[b] = a; } }; void solve(int tc) { int n, q; cin >> n >> q; UFDS ufds(2*n); while (q--) { char x; int a, b; cin >> x >> a >> b; --a, --b; if (x == 'Q') { if (ufds.same(a, b)) cout << 'R' << '\n'; else if (ufds.same(a+n, b)) cout << 'A' << '\n'; else cout << '?' << '\n'; } else { if (x == 'R') { ufds.unite(a, b); ufds.unite(a+n, b+n); } else { ufds.unite(a+n, b); ufds.unite(a, b+n); } } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); 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...