Submission #1285534

#TimeUsernameProblemLanguageResultExecution timeMemory
1285534lyra_g13Experimental Charges (NOI19_charges)C++20
43 / 100
1096 ms2060 KiB
#include <bits/stdc++.h> using ll = long long; class djf{ public: ll n; std::vector<ll> par; djf(ll n) : n(n) , par(n+1) { for(int i = 1 ; i<=n ; i++){ par[i] = i; } }; ll root(ll x){ if(par[x] ==x){ return x; } return root(par[x]); } void merge(ll u , ll v){ u = root(u); v = root(v); if(u == v) return; par[v] = u; } }; int main(){ std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); ll n , q; std::cin >> n >> q; djf s(2*n); while(q--){ char c; ll a , b; std::cin >> c >> a >> b; if(c == 'A'){ s.merge(a, b+n); s.merge(a+n , b); } else if(c == 'R'){ s.merge(a , b); s.merge(a+n , b+n); } else{ if(s.root(a) == s.root(b)){ std::cout << "R\n"; } else if(s.root(a) == s.root(b+n)){ std::cout << "A\n"; } else{ std::cout << "?\n"; } } } }
#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...