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 MAX_N = 50000;
string a[MAX_N], b[MAX_N];
map<string, vector<string> > graph;
map<string, int> vartable;
map<string, bool> viz;
bool ok = true;
int getVal(string str) {
if(!viz[str]) {
viz[str] = true;
int finalVal = -1;
if(vartable.count(str) > 0)
finalVal = vartable[str];
vartable[str] = -1;
for(auto it: graph[str]) {
if(finalVal == -1)
finalVal = getVal(str);
else {
int val2 = getVal(str);
if(val2 != finalVal)
ok = false;
}
}
vartable[str] = finalVal;
}
return vartable[str];
}
int main() {
int N;
bool ok = true;
cin >> N;
for(int i = 0; i < N; ++i)
cin >> a[i];
for(int i = 0; i < N; ++i)
cin >> b[i];
for(int i = 0; i < N; ++i) {
if(isalpha(a[i][0]) && isalpha(b[i][0])) {
if(a != b) {
graph[a[i]].push_back(b[i]);
graph[b[i]].push_back(a[i]);
}
} else if(isalpha(a[i][0])) {
int valB = atoi(b[i].c_str());
if(vartable.count(a[i]) > 0 && vartable[a[i]] != valB)
ok = false;
else {
vartable[b[i]] = valB;
}
} else if(isalpha(b[i][0])) {
int valA = atoi(a[i].c_str());
if(vartable.count(b[i]) > 0 && vartable[b[i]] != valA)
ok = false;
else
vartable[b[i]] = valA;
} else if(atoi(a[i].c_str()) != atoi(b[i].c_str()))
ok = false;
}
for(auto it: vartable)
getVal(it.first);
if(ok)
printf("DA");
else
printf("NE");
return 0;
}
# | 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... |