Submission #756579

# Submission time Handle Problem Language Result Execution time Memory
756579 2023-06-12T00:42:22 Z Pring Zamjena (COCI18_zamjena) C++14
14 / 70
12 ms 10324 KB
#include <bits/stdc++.h>
using namespace std;

const int MXN = 100005;
int n;
string a[MXN], b[MXN];
int na[MXN], nb[MXN];
map<string, int> M;

inline bool isNumber(string &s) {
    return ('0' <= s[0] && s[0] <= '9');
}

struct DSU {
    string s[MXN];
    int p[MXN], sz[MXN];
    void init(int _n) {
        for (int i = 0; i < _n; i++) {
            p[i] = i;
            sz[i] = 1;
        }
    }
    int find(int x) {
        return (x == p[x] ? x : p[x] = find(p[x]));
    }
    bool onion(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return true;
        if (isNumber(s[x]) && isNumber(s[y])) return false;
        // if (sz[x] < sz[y]) swap(x, y);
        if (!isNumber(s[y])) swap(x, y);
        sz[x] += sz[y];
        p[y] = x;
        return true;
    }
} dsu;

void CIN(string &s, int &x) {
    cin >> s;
    auto it = M.find(s);
    if (it == M.end()) {
        dsu.s[M.size()] = s;
        x = M.size();
        M[s] = x;
    } else {
        x = it -> second;
    }
}

bool check() {
    for (int i = 0; i < n; i++) {
        if (!dsu.onion(na[i], nb[i])) return false;
    }
    return true;
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++) {
        CIN(a[i], na[i]);
    }
    for (int i = 0; i < n; i++) {
        CIN(b[i], nb[i]);
    }
    dsu.init(M.size());
    cout << (check() ? "DA" : "NE") << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 8 ms 9644 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Incorrect 5 ms 9684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9672 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 5 ms 9684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 8 ms 9940 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 10324 KB Output isn't correct
2 Halted 0 ms 0 KB -