This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// NK
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr)
void solve(){
vector<string> a, b;
int n; cin>>n;
for (int i=0; i<n; i++){
string x; cin>>x;
a.pb(x);
}
for (int i=0; i<n; i++){
string x; cin>>x;
b.pb(x);
}
vi g[n*2+10];
vector<bool> vis(n*2+10);
map<string, int> helper;
map<int, string> vic;
int pos = 0;
for (int i=0; i<n; i++){
auto ff = helper.find(a[i]);
if (ff == helper.end()) helper[a[i]] = pos, vic[pos++] = a[i];
ff = helper.find(b[i]);
if (ff == helper.end()) helper[b[i]] = pos, vic[pos++] = b[i];
}
for (int i=0; i<n; i++){
g[helper[a[i]]].pb(helper[b[i]]);
g[helper[b[i]]].pb(helper[a[i]]);
}
for (auto i=helper.begin(); i!=helper.end(); i++){
if (!vis[i->second]){
stack<int> dfs;
dfs.push(i->second);
vis[i->second] = true;
set<int> checker;
while(!dfs.empty()){
int u = dfs.top();
dfs.pop();
if ('0' <= vic[u][0] && vic[u][0] <= '9') checker.insert(stoi(vic[u]));
for (int j=0; j<g[u].size(); j++){
int v = g[u][j];
if (!vis[v]){
vis[v] = true;
dfs.push(v);
}
}
}
if (checker.size() > 1){
cout<<"NE"<<'\n';
return;
}
}
}
cout<<"DA\n";
}
int main(){
Bolivia_is_nice;
int t; t = 1; //cin>>t;
while(t--)
solve();
return 0;
}
/*
~/.emacs
*/
Compilation message (stderr)
zamjena.cpp: In function 'void solve()':
zamjena.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j=0; j<g[u].size(); j++){
| ~^~~~~~~~~~~~
# | 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... |