// 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
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++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
7 ms |
1152 KB |
Output is correct |
4 |
Correct |
8 ms |
1152 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
7 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2684 KB |
Output is correct |
2 |
Correct |
55 ms |
5352 KB |
Output is correct |
3 |
Correct |
98 ms |
8432 KB |
Output is correct |
4 |
Correct |
131 ms |
10212 KB |
Output is correct |
5 |
Correct |
238 ms |
14820 KB |
Output is correct |
6 |
Correct |
139 ms |
10596 KB |
Output is correct |