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 <iostream>
#include <sstream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 5e4 + 37;
unordered_map <string, int> mp;
unordered_map <string, vector <string> > v;
string s[maxn], t[maxn];
int integer (string s) {
stringstream geek (s);
int x = 0;
geek >> x;
return x;
}
bool isinteger (string s) {
if ((int)(s[0] - '0') <= 10)
return 1;
return 0;
}
void dfs (string now, int x) {
mp[now] = x;
for (auto w : v[now])
if (!mp.count (w))
dfs (w, x);
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int k = 1; k <= 10; k++) {
for (int i = 0; i < n; i++) {
if (isinteger (s[i])) {
if (isinteger (t[i])) {
if (s[i] != t[i]) {
return cout << "NE" << endl, 0;
}
}
else {
int x = integer (s[i]);
if (!mp.count (t[i])) {
dfs (t[i], x);
}
if (!mp.count (t[i]) or mp[t[i]] == x)
mp[t[i]] = x;
else
return cout << "NE" << endl, 0;
}
}
else {
if (isinteger (t[i])) {
int x = integer (t[i]);
if (!mp.count (s[i])) {
dfs (s[i], x);
}
if (!mp.count (s[i]) or mp[s[i]] == x)
mp[s[i]] = x;
else
return cout << "NE" << endl, 0;
}
else {
if (mp.count (s[i])) {
if (mp.count (t[i])) {
if (mp[s[i]] != mp[t[i]])
return cout << "NE" << endl, 0;
}
else {
mp[t[i]] = mp[s[i]];
}
}
else if (mp.count (t[i])) {
mp[s[i]] = mp[t[i]];
}
v[s[i]].PB (t[i]);
v[t[i]].PB (s[i]);
}
}
}
}
cout << "DA" << endl;
}
# | 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... |