Submission #756580

#TimeUsernameProblemLanguageResultExecution timeMemory
756580PringZamjena (COCI18_zamjena)C++14
70 / 70
61 ms13884 KiB
#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); // cout << s[x] << ' ' << s[y] << endl; 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]); } // for (int i = 0; i < n; i++) cout << na[i] << ' ' << nb[i] << endl; dsu.init(M.size()); cout << (check() ? "DA" : "NE") << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...