Submission #95403

#TimeUsernameProblemLanguageResultExecution timeMemory
95403dalgerokZamjena (COCI18_zamjena)C++14
70 / 70
176 ms7708 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int sz, p[N], cnt[N]; map < string, int > q; int dsu_get(int v){ return p[v] ? p[v] = dsu_get(p[v]) : v; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin >> n; int sz = 0; string a[n + 1]; for(int i = 1; i <= n; i++){ cin >> a[i]; if(q.find(a[i]) == q.end()){ q[a[i]] = ++sz; } } string b[n + 1]; for(int i = 1; i <= n; i++){ cin >> b[i]; if(q.find(b[i]) == q.end()){ q[b[i]] = ++sz; } if(dsu_get(q[a[i]]) != dsu_get(q[b[i]])){ p[dsu_get(q[a[i]])] = dsu_get(q[b[i]]); } } for(auto it : q){ if(isdigit(it.first[0])){ cnt[dsu_get(it.second)] += 1; } } for(int i = 1; i <= sz; i++){ if(cnt[i] > 1){ return cout << "NE", 0; } } cout << "DA"; }
#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...