Submission #1025597

#TimeUsernameProblemLanguageResultExecution timeMemory
1025597vjudge1Zamjena (COCI18_zamjena)C++17
0 / 70
46 ms4180 KiB
#include <bits/stdc++.h> using namespace std; int MAX_N=100000; map<string, string>p; map<string, int>sz; string Find(string i) { if(p[i]==i) { return i; } return p[i]=Find(p[i]); } bool Union(string a, string b) { a=Find(a); b=Find(b); if(isdigit(a[0]) && isdigit(b[0])) { if(a!=b) return false; else return 1; } if(isdigit(a[0])) { p[b]=a; sz[a]+=sz[b]; return 1; } if(isdigit(b[0])) { p[a]=b; sz[b]+=sz[a]; return 1; } if(a!=b) { if(sz[a]>sz[b]) { swap(a, b); } p[a]=b; sz[b]+=sz[a]; } return 1; } int main() { int n; cin>>n; string a[n], b[n]; for(int i=0; i<n; i++) { cin>>a[i]; p[a[i]]=a[i]; sz[a[i]]=1; } for(int i=0; i<n; i++) { cin>>b[i]; p[b[i]=b[i]]; sz[a[i]]=1; } bool kiki=0; for(int i=0; i<n; i++) { if(!Union(a[i], b[i])) { kiki=1; } } if(kiki) { cout<<"NE"; return 0; } else { 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...