Submission #1026748

#TimeUsernameProblemLanguageResultExecution timeMemory
1026748kkkkkkkkZamjena (COCI18_zamjena)C++14
70 / 70
170 ms12324 KiB
#include <bits/stdc++.h> using namespace std; map<string, string> parent; map<string, int> sz; string Find(string x) { if (parent[x]==x) return x; return parent[x]=Find(parent[x]); } bool Union(string a, string b) { a=Find(a), b=Find(b); if (a[0]-'0'<=9&&b[0]-'0'<=9) return a==b; if (a[0]-'0'<=9) { parent[b]=a; sz[a]+=sz[b]; return 1; } if (b[0]-'0'<=9) { parent[a]=b; sz[b]+=sz[a]; return 1; } if (a==b) return 1; if (sz[a]<sz[b]) swap(a,b); sz[a]+=sz[b]; parent[b]=a; return 1; } int main() { int n; cin >> n; string a[n], b[n]; for (int i=0;i<n;i++) { cin >> a[i]; parent[a[i]]=a[i]; sz[a[i]]=1; } for (int i=0;i<n;i++) { cin >> b[i]; parent[b[i]]=b[i]; sz[b[i]]=1; } for (int i=0;i<n;i++) { if (!Union(a[i], b[i])) { cout << "NE"; return 0; } } 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...