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;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
string a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i];
}
string b[n + 1];
for(int i = 1; i <= n; i++){
cin >> b[i];
}
map < string, string > q;
vector < pair < string, string > > e;
for(int i = 1; i <= n; i++){
if(isdigit(a[i][0]) && isdigit(b[i][0])){
if(a[i] != b[i]){
return cout << "NE", 0;
}
}
else if(isdigit(a[i][0]) && !isdigit(b[i][0])){
if(q.find(b[i]) == q.end()){
q[b[i]] = a[i];
}
else if(a[i] != q[b[i]]){
return cout << "NE", 0;
}
}
else if(!isdigit(a[i][0]) && isdigit(b[i][0])){
if(q.find(a[i]) == q.end()){
q[a[i]] = b[i];
}
else if(b[i] != q[a[i]]){
return cout << "NE", 0;
}
}
else{
if(a[i] == b[i]){
continue;
}
e.push_back(make_pair(a[i], b[i]));
}
}
for(auto it : e){
string s = it.first, t = it.second;
if(q.find(s) == q.end() && q.find(t) == q.end()){
}
else if(q.find(s) == q.end() && q.find(t) != q.end()){
q[s] = q[t];
}
else if(q.find(s) != q.end() && q.find(t) == q.end()){
q[t] = q[s];
}
else if(q[s] != q[t]){
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... |