#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;
void getVal(string str, int xd) {
if(!viz[str]) {
viz[str] = true;
if(vartable.count(str) > 0 && vartable[str] != xd)
ok = false;
vartable[str] = xd;
for(auto it: graph[str])
getVal(it, xd);
}
}
int main() {
int N;
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[a[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, it.second);
if(ok)
printf("DA");
else
printf("NE");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
4 ms |
3448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
4 ms |
3448 KB |
Output is correct |
3 |
Correct |
4 ms |
3452 KB |
Output is correct |
4 |
Correct |
4 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3492 KB |
Output is correct |
2 |
Correct |
5 ms |
3448 KB |
Output is correct |
3 |
Correct |
4 ms |
3448 KB |
Output is correct |
4 |
Correct |
4 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3448 KB |
Output is correct |
6 |
Correct |
5 ms |
3452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3704 KB |
Output is correct |
2 |
Correct |
7 ms |
3704 KB |
Output is correct |
3 |
Correct |
13 ms |
4216 KB |
Output is correct |
4 |
Correct |
15 ms |
4472 KB |
Output is correct |
5 |
Correct |
14 ms |
4216 KB |
Output is correct |
6 |
Correct |
12 ms |
4088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
6128 KB |
Output is correct |
2 |
Correct |
73 ms |
8312 KB |
Output is correct |
3 |
Correct |
138 ms |
12052 KB |
Output is correct |
4 |
Correct |
168 ms |
12536 KB |
Output is correct |
5 |
Correct |
282 ms |
18864 KB |
Output is correct |
6 |
Correct |
179 ms |
13084 KB |
Output is correct |