제출 #228183

#제출 시각아이디문제언어결과실행 시간메모리
228183VEGAnnZamjena (COCI18_zamjena)C++14
70 / 70
33 ms4656 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100100; unordered_map<string, int> mem; int n, b[N], a[N], lst = 0, pr[N]; string s; bool num[N], mrk[N]; int get(int x) { return (pr[x] == x ? x : pr[x] = get(pr[x])); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> s; if (mem.find(s) == mem.end()) { num[lst] = bool(s[0] - '0' < 10); a[i] = mem[s] = lst++; } else a[i] = mem[s]; } for (int i = 0; i < n; i++) { cin >> s; if (mem.find(s) == mem.end()) { num[lst] = bool(s[0] - '0' < 10); b[i] = mem[s] = lst++; } else b[i] = mem[s]; } for (int i = 0; i < lst; i++) pr[i] = i; for (int i = 0; i < n; i++){ int x = get(a[i]), y = get(b[i]); if (x == y) continue; pr[x] = y; } for (int i = 0; i < lst; i++){ if (!num[i]) continue; int gt = get(i); if (mrk[gt]){ cout << "NE"; return 0; } mrk[gt] = 1; } cout << "DA"; 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...