Submission #653960

#TimeUsernameProblemLanguageResultExecution timeMemory
653960true22Experimental Charges (NOI19_charges)C++14
32 / 100
27 ms3676 KiB
#include <bits/stdc++.h> using namespace std; // short forms // #define nl "\n" #define pb push_back #define f first #define s second #define ll long long int #define ld long double #define mp make_pair #define all(x) x.begin(), x.end() // debug // #define pv(x) for(auto k : x){cout << k << " ";} cout << nl; #define pp(x) cout << x.f << " " << x.s << nl; #define bv(x) if (x) cout << "true"; else cout << "false"; #define gp(x, y) x << " " << y // loop // #define FOR(i, a, b) for(ll i = a; i <=b; i++) // pair // typedef pair<ll, ll> pl; // vector // typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pl> vp; // constants // const ll INF = 1e17; const ll mod = 1e9 + 7; const ll S = 1e5 + 5; ll n, siz[S], link[S], eof[S]; ll find(ll a){ ll st = a; while(a != link[a]) a = link[a]; //path compression while(st != link[st]){ ll tmp = link[st]; link[st] = a; st = tmp; } return a; } ll unite(ll a, ll b){ // returns the rep of the bigger set a = find(a); b = find(b); if (a == b) return a; // union by size if (siz[a] < siz[b]) swap(a, b); siz[a] += siz[b]; link[b] = a; return a; } void solve(){ FOR(i, 0, S-1){ link[i] = i; siz[i] = 1; eof[i] = -1; } ll q; cin >> n >> q; while(q--){ char t; ll a, b; cin >> t; cin >> a >> b; if (t == 'A'){ // set enemies a = find(a); b = find(b); if (a == b) continue; eof[a] = b; eof[b] = a; if (eof[a] != -1) unite(eof[a], b); if (eof[b] != -1) unite(eof[b], a); } else if (t == 'R'){ a = find(a); b = find(b); if (eof[a] == b) continue; ll ae, be; ae = eof[a]; be = eof[b]; ae = unite(ae, be); a = unite(a, b); eof[a] = ae; if (ae != -1) eof[ae] = a; } else{ // query a = find(a); b = find(b); if (a == b) cout << 'R' << nl; else if (eof[a] == b || eof[b] == a) cout << 'A' << nl; else cout << '?' << nl; } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); ll t = 1; //cin >> t; while(t--){ solve(); } 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...