이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
    while(a != link[a]) a= link[a];
    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;
    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
            ll set1, set2;
            set1 = find(a);
            set2 = find(b);
            if (eof[set1] == -1)
                eof[set1] = b;
            else
                unite(eof[set1], b);
            if (eof[set2] == -1)
                eof[set2] = a;
            else
                unite(eof[set2], a);
        }
        else if (t == 'R'){
            // set friends
            a = find(a);
            b = find(b);
            ll biggerset = unite(a, b);
            if (eof[a] != -1 && eof[b] != -1)
                unite(eof[a], eof[b]);
            ll otherset;
            if (biggerset == a)
                otherset = b;
            else
                otherset = a;
            if (eof[biggerset] == -1)
                eof[biggerset] = eof[otherset];
        }
        else{
            // query
            a = find(a);
            b = find(b);
            if (a == b)
                cout << 'R' << nl;
            else if (eof[a] != -1 && (find(eof[a]) == find(b)))
                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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |