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>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 50 * 1000 + 10;
int n;
int a[nax];
vi V[nax];
map<string, int> sc;
int nr;
bool vis[nax];
vi cur;
void dfs(int x) {
vis[x] = true;
cur.PB(x);
for(int nbh : V[x]) if(!vis[nbh]) dfs(nbh);
}
int main() {_
cin >> n;
for(int i = 0; i < n; ++i) {
string s;
cin >> s;
if(s[0] >= '0' && s[0] <= '9') {
int num = atoi(s.c_str());
a[i] = -num;
} else {
if(!sc.count(s)) sc[s] = ++nr;
a[i] = sc[s];
}
}
for(int i = 0; i < n; ++i) {
string s;
cin >> s;
if(s[0] >= '0' && s[0] <= '9') {
int num = atoi(s.c_str());
if(a[i] < 0 && a[i] != -num) {
cout << "NE";
return 0;
}
a[i] = -num;
} else {
if(!sc.count(s)) sc[s] = ++nr;
if(a[i] > 0) {
V[sc[s]].PB(a[i]);
V[a[i]].PB(sc[s]);
}
}
}
for(int i = 1; i <= nr; ++i) {
if(!vis[i]) {
cur.clear();
dfs(i);
int last = 0;
for(int x : cur) {
if(a[x] < 0) {
if(last == 0) last = a[x];
else if(last != a[x]) {
cout << "NE";
return 0;
}
}
}
}
}
cout << "DA";
}
# | 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... |