Submission #491640

# Submission time Handle Problem Language Result Execution time Memory
491640 2021-12-03T16:02:51 Z Jomnoi Experimental Charges (NOI19_charges) C++17
100 / 100
27 ms 2512 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
using pii = pair <int, int>;

const int N = 1e5 + 10;

int parent[2 * N];

int root(int u) {
    if(u == parent[u]) {
        return u;
    }
    return parent[u] = root(parent[u]);
}

void Union(int u, int v) {
    parent[root(u)] = root(v);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= 2 * n; i++) {
        parent[i] = i;
    }
    while(q--) {
        char t;
        int a, b;
        cin >> t >> a >> b;
        if(t == 'R') {
            Union(a, b);
            Union(a + n, b + n);
        }
        else if(t == 'A') {
            Union(a, b + n);
            Union(a + n, b);
        }
        else {
            if(root(a) == root(b) && root(a) == root(b + n)) {
                cout << "?\n";
            }
            else if(root(a) == root(b + n)) {
                cout << "A\n";
            }
            else if(root(a) == root(b)) {
                cout << "R\n";
            }
            else {
                cout << "?\n";
            }
        }

        if(DEBUG) {
            for(int i = 1; i <= 2 * n; i++) {
                cout << i << " " << root(i) << endl;
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1088 KB Output is correct
2 Correct 21 ms 1956 KB Output is correct
3 Correct 23 ms 1960 KB Output is correct
4 Correct 22 ms 1996 KB Output is correct
5 Correct 21 ms 1952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 1136 KB Output is correct
2 Correct 22 ms 2376 KB Output is correct
3 Correct 26 ms 2412 KB Output is correct
4 Correct 27 ms 2380 KB Output is correct
5 Correct 27 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1704 KB Output is correct
2 Correct 20 ms 2500 KB Output is correct
3 Correct 24 ms 2320 KB Output is correct
4 Correct 26 ms 2380 KB Output is correct
5 Correct 25 ms 2344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 320 KB Output is correct
6 Correct 1 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 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 320 KB Output is correct
6 Correct 19 ms 1088 KB Output is correct
7 Correct 21 ms 1956 KB Output is correct
8 Correct 23 ms 1960 KB Output is correct
9 Correct 22 ms 1996 KB Output is correct
10 Correct 21 ms 1952 KB Output is correct
11 Correct 25 ms 1136 KB Output is correct
12 Correct 22 ms 2376 KB Output is correct
13 Correct 26 ms 2412 KB Output is correct
14 Correct 27 ms 2380 KB Output is correct
15 Correct 27 ms 2512 KB Output is correct
16 Correct 18 ms 1704 KB Output is correct
17 Correct 20 ms 2500 KB Output is correct
18 Correct 24 ms 2320 KB Output is correct
19 Correct 26 ms 2380 KB Output is correct
20 Correct 25 ms 2344 KB Output is correct
21 Correct 1 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 0 ms 332 KB Output is correct
26 Correct 23 ms 2384 KB Output is correct
27 Correct 24 ms 2356 KB Output is correct
28 Correct 24 ms 2336 KB Output is correct
29 Correct 24 ms 2244 KB Output is correct
30 Correct 23 ms 2360 KB Output is correct