#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i,a,b) for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 1e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ =320;
const long double EPS = 1e-7;
bool isVar(string s){
if(isdigit(s[0]))return false;
return true;
}
map<string, set<string> > mt;
map<string, set<string> > adj;
set<string> vis;
set<string> kk;
void dfs(string node){
if(vis.count(node))
return;
vis.insert(node);
for(auto x : mt[node])kk.insert(x);
for(auto to : adj[node]){
dfs(to);
}
}
int32_t main(){
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
int n;
cin >> n;
vector<string> vs1(n), vs2(n);
f(i,0,n)cin >> vs1[i];
f(i,0,n)cin >> vs2[i];
vector<string> vt;
f(i,0,n){
if(isVar(vs1[i]))vt.pb(vs1[i]);
if(isVar(vs2[i]))vt.pb(vs2[i]);
if(vs1[i] != vs2[i]){
if(isVar(vs1[i]) && isVar(vs2[i])){
adj[vs1[i]].insert(vs2[i]);
adj[vs2[i]].insert(vs1[i]);
} else if(isVar(vs1[i])){
mt[vs1[i]].insert(vs2[i]);
} else if(isVar(vs2[i])){
mt[vs2[i]].insert(vs1[i]);
} else {
cout << "NE\n"; return 0;
}
}
}
sort(vt.begin(),vt.end());
vt.resize(unique(vt.begin(),vt.end())-vt.begin());
for(auto var : vt){
kk.clear();
dfs(var);
if(kk.size() > 1){
cout << "NE\n"; return 0;
}
}
cout << "DA\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
360 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
892 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
13 ms |
1784 KB |
Output is correct |
4 |
Correct |
11 ms |
1652 KB |
Output is correct |
5 |
Correct |
14 ms |
1780 KB |
Output is correct |
6 |
Correct |
11 ms |
1396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
4904 KB |
Output is correct |
2 |
Correct |
104 ms |
9928 KB |
Output is correct |
3 |
Correct |
191 ms |
16848 KB |
Output is correct |
4 |
Correct |
186 ms |
16864 KB |
Output is correct |
5 |
Correct |
408 ms |
29664 KB |
Output is correct |
6 |
Correct |
254 ms |
20656 KB |
Output is correct |