Submission #1292479

#TimeUsernameProblemLanguageResultExecution timeMemory
1292479chaitanyamehtaLost Array (NOI19_lostarray)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>

struct DSU {
    // ... (your DSU unchanged)
};

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n, q;
    cin >> n >> q;
    DSU dsu;
    dsu.init(n);
    
    // Use map for sparse relations (keys are sorted pairs of roots)
    map<pii, int> relations;  // or unordered_map with hash for pii
    
    while (q--) {
        char t;
        cin >> t;
        int u, v;
        cin >> u >> v;
        
        int pu = dsu.find(u), pv = dsu.find(v);
        if (t == 'Q') {
            if (pu == pv) {
                cout << "R\n";
            } else {
                pii key = {min(pu, pv), max(pu, pv)};
                cout << (relations[key] ? "A\n" : "?\n");
            }
        } else if (t == 'A') {
            if (pu != pv) {  // Ignore if same
                pii key = {min(pu, pv), max(pu, pv)};
                relations[key] = 1;
            }
        } else {  // 'C' - union
            if (pu != pv) {
                // TODO: Merge relations from pu and pv into new root
                // E.g., iterate over current neighbors of pu/pv and add to new root
                dsu.Union(u, v);
            }
        }
    }
}

Compilation message (stderr)

lostarray.cpp: In function 'int main()':
lostarray.cpp:15:9: error: 'struct DSU' has no member named 'init'
   15 |     dsu.init(n);
      |         ^~~~
lostarray.cpp:26:22: error: 'struct DSU' has no member named 'find'
   26 |         int pu = dsu.find(u), pv = dsu.find(v);
      |                      ^~~~
lostarray.cpp:28:23: error: 'pv' was not declared in this scope; did you mean 'pu'?
   28 |             if (pu == pv) {
      |                       ^~
      |                       pu
lostarray.cpp:31:52: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<long long int, long long int>'
   31 |                 pii key = {min(pu, pv), max(pu, pv)};
      |                                                    ^
      |                                                    |
      |                                                    <brace-enclosed initializer list>
lostarray.cpp:35:23: error: 'pv' was not declared in this scope; did you mean 'pu'?
   35 |             if (pu != pv) {  // Ignore if same
      |                       ^~
      |                       pu
lostarray.cpp:36:52: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<long long int, long long int>'
   36 |                 pii key = {min(pu, pv), max(pu, pv)};
      |                                                    ^
      |                                                    |
      |                                                    <brace-enclosed initializer list>
lostarray.cpp:40:23: error: 'pv' was not declared in this scope; did you mean 'pu'?
   40 |             if (pu != pv) {
      |                       ^~
      |                       pu
lostarray.cpp:43:21: error: 'struct DSU' has no member named 'Union'
   43 |                 dsu.Union(u, v);
      |                     ^~~~~