This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |