Submission #197859

#TimeUsernameProblemLanguageResultExecution timeMemory
197859Osama_AlkhodairyZamjena (COCI18_zamjena)C++17
70 / 70
314 ms8904 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x){cout << x << endl; exit(0);} #define ll long long int n; vector <string> a, b; map <string, string> p; bool num(string &x){ return '0' <= x[0] && x[0] <= '9'; } string find(string x){ if(p[x] == x) return x; return p[x] = find(p[x]); } void merge(string a, string b){ a = find(a); b = find(b); p[a] = b; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(n); for(auto &i : a) cin >> i; b.resize(n); for(auto &i : b) cin >> i; for(int i = 0 ; i < n ; i++){ p[a[i]] = a[i]; p[b[i]] = b[i]; } for(int i = 0 ; i < n ; i++){ merge(a[i], b[i]); } set <string> nums; for(int i = 0 ; i < n ; i++){ if(num(a[i])) nums.insert(a[i]); if(num(b[i])) nums.insert(b[i]); } set <string> all; for(auto &i : nums) all.insert(find(i)); if(all.size() != nums.size()) cout << "NE\n"; else cout << "DA\n"; }
#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...