#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;
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);
if(ok)
printf("DA");
else
printf("NE");
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
Output is correct |
2 |
Correct |
5 ms |
3420 KB |
Output is correct |
3 |
Correct |
5 ms |
3448 KB |
Output is correct |
4 |
Correct |
5 ms |
3448 KB |
Output is correct |
5 |
Correct |
5 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
5 ms |
3448 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
3448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
3580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
4984 KB |
Output is correct |
2 |
Incorrect |
47 ms |
6776 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |