#include <iostream>
#include <map>
#include <set>
using namespace std;
int n, i;
string arr[50000], x;
map <string, int> m;
map <string, set <string>> eq;
inline const int v(const string &k) {
return isdigit(k[0]) ? stoi(k) : m[k];
}
inline void s(const string &k, const int &i) {
m[k] = i;
string e;
while (!eq[k].empty()) {
e = *prev(eq[k].end());
eq[k].erase(prev(eq[k].end()));
s(e, i);
}
}
int main() {
ios::sync_with_stdio(); cin.tie(0); cout.tie(0);
cin >> n;
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < n; i++) {
cin >> x;
if (arr[i] == x);
else if (v(arr[i]) && v(x)) {
if (v(arr[i]) != v(x)) {
cout << "NE";
return 0;
}
}
else if (v(arr[i])) s(x, v(arr[i]));
else if (v(x)) s(arr[i], v(x));
else {
eq[arr[i]].insert(x);
eq[x].insert(arr[i]);
}
}
cout << "DA";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1748 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1748 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
1 ms |
1748 KB |
Output is correct |
5 |
Correct |
1 ms |
1748 KB |
Output is correct |
6 |
Correct |
1 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2004 KB |
Output is correct |
3 |
Correct |
4 ms |
2260 KB |
Output is correct |
4 |
Correct |
7 ms |
2604 KB |
Output is correct |
5 |
Correct |
5 ms |
2388 KB |
Output is correct |
6 |
Correct |
4 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3336 KB |
Output is correct |
2 |
Correct |
43 ms |
5032 KB |
Output is correct |
3 |
Correct |
66 ms |
8028 KB |
Output is correct |
4 |
Correct |
42 ms |
7124 KB |
Output is correct |
5 |
Correct |
168 ms |
14192 KB |
Output is correct |
6 |
Correct |
85 ms |
6800 KB |
Output is correct |