답안 #491432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
491432 2021-12-02T06:41:56 Z Joo Experimental Charges (NOI19_charges) C++17
100 / 100
28 ms 2556 KB
#include <bits/stdc++.h>
using namespace std;


const int N = 2e5+10;
int cp[N], n, Q;

int fi(int x){ return cp[x] = (cp[x] == x) ? x : fi(cp[x]); }

void uni(int u, int v){
    u = fi(u), v = fi(v);
    cp[v] = u;
    return;
}


int main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> Q;
    for(int i = 1; i <= 2*n; i++) cp[i] = i;

    while(Q--){
        char op; int u, v; cin >> op >> u >> v;

        if(op == 'A'){ //differ
            uni(u, v+n);
            uni(u+n, v);
        } else if (op == 'R'){ //same
            uni(u, v);
            uni(u+n, v+n);
        } else {
            //cout << fi(u) << " " << fi(v) << "  " << fi(u+n) << " " << fi(v+n) << "\n";
            if(fi(u) == fi(v)) cout << "R\n";
            else if(fi(u) == fi(v+n)) cout << "A\n";
            else cout << "?\n";
        }

    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1956 KB Output is correct
2 Correct 21 ms 2016 KB Output is correct
3 Correct 22 ms 2040 KB Output is correct
4 Correct 19 ms 2068 KB Output is correct
5 Correct 22 ms 1988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2412 KB Output is correct
2 Correct 23 ms 2372 KB Output is correct
3 Correct 24 ms 2380 KB Output is correct
4 Correct 24 ms 2372 KB Output is correct
5 Correct 25 ms 2500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2336 KB Output is correct
2 Correct 22 ms 2556 KB Output is correct
3 Correct 23 ms 2384 KB Output is correct
4 Correct 28 ms 2376 KB Output is correct
5 Correct 24 ms 2320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 26 ms 1956 KB Output is correct
7 Correct 21 ms 2016 KB Output is correct
8 Correct 22 ms 2040 KB Output is correct
9 Correct 19 ms 2068 KB Output is correct
10 Correct 22 ms 1988 KB Output is correct
11 Correct 24 ms 2412 KB Output is correct
12 Correct 23 ms 2372 KB Output is correct
13 Correct 24 ms 2380 KB Output is correct
14 Correct 24 ms 2372 KB Output is correct
15 Correct 25 ms 2500 KB Output is correct
16 Correct 22 ms 2336 KB Output is correct
17 Correct 22 ms 2556 KB Output is correct
18 Correct 23 ms 2384 KB Output is correct
19 Correct 28 ms 2376 KB Output is correct
20 Correct 24 ms 2320 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 22 ms 2428 KB Output is correct
27 Correct 27 ms 2376 KB Output is correct
28 Correct 24 ms 2344 KB Output is correct
29 Correct 23 ms 2248 KB Output is correct
30 Correct 23 ms 2320 KB Output is correct