#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 1000000007
#define lim 200005
using namespace std;
map<string, string> dad;
string find(string s){
if(dad[s]=="" || dad[s]==s) return dad[s]=s;
return dad[s]=find(dad[s]);
}
void unite(string s, string t){
dad[find(s)] = find(t);
}
void solve(){
int n; cin >> n;
map<string, string> asso;
string b1[n+1], b2[n+1];
vector<pair<string, string>> pro; // variba, numba
for(int i=1; i<=n; i++) cin >> b1[i];
for(int i=1; i<=n; i++) cin >> b2[i];
for(int i=1; i<=n; i++){
string s=b1[i], t=b2[i];
if((s[0]-'0')>=0 && (s[0]-'0')<=9){ // numba
if((t[0]-'0')>=0 && (t[0]-'0')<=9){ // numba
if(s!=t){
cout << "NE\n";
return;
}
}
else{ // variba
pro.pb({t,s});
}
}
else{ // variba
if((t[0]-'0')>=0 && (t[0]-'0')<=9){ // numba
pro.pb({s,t});
}
else{ // variba
unite(s,t);
}
}
}
for(auto p:pro){
if(asso[find(p.st)]==""){
asso[find(p.st)]=p.nd;
}
else{
if(asso[find(p.st)]!=p.nd){
cout << "NE\n";
return;
}
}
}
cout << "DA" << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
ll t=1;
//cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
420 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
860 KB |
Output is correct |
4 |
Correct |
8 ms |
724 KB |
Output is correct |
5 |
Correct |
6 ms |
888 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
1588 KB |
Output is correct |
2 |
Correct |
41 ms |
3288 KB |
Output is correct |
3 |
Correct |
88 ms |
4732 KB |
Output is correct |
4 |
Correct |
75 ms |
6600 KB |
Output is correct |
5 |
Correct |
175 ms |
8272 KB |
Output is correct |
6 |
Correct |
124 ms |
5948 KB |
Output is correct |