//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define MAX 200007
#define pb push_back
#define mp make_pair
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>>
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first : key
// myMap.begin()->second : value
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;;b>>=1;}return ans;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sum(int a,int b){return ((a%mod)+(b%mod))%mod;}
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
void solve(){
int n; cin>>n;
vector<string> a(n); for(int i=0;i<n;i++) cin>>a[i];
vector<string> b(n); for(int i=0;i<n;i++) cin>>b[i];
map<string,set<string>> mp;
map<string,string> bas;
for(int i=0;i<n;i++){
if(a[i].size()==1 && a[i][0]<'a' && b[i].size()==1 && b[i][0]<'a' && a[i]!=b[i]){cout<<"NE\n";return;}
if(a[i]==b[i]) continue;
else{
if(bas[a[i]]=="" && bas[b[i]]==""){
bas[a[i]]=a[i];
bas[b[i]]=a[i];
mp[a[i]].insert(b[i]);
mp[a[i]].insert(a[i]);
}
else if(bas[a[i]]!="" && bas[b[i]]!=""){
//{cout<<"NE\n";return;}
if(bas[a[i]]==bas[b[i]]) continue;
if(mp[bas[a[i]]].size()<mp[bas[b[i]]].size()) swap(mp[bas[a[i]]],mp[bas[b[i]]]);
string tmp=bas[b[i]];
for(auto u : mp[bas[b[i]]]){
mp[bas[a[i]]].insert(u);
bas[u]=bas[a[i]];
}
mp[tmp].clear();
// mp[bas[a[i]]].insert(b[i]); mp[bas[b[i]]].insert(a[i]);
}
else{
if(bas[a[i]]!=""){
if(b[i][0]>='a')bas[b[i]]=bas[a[i]];
mp[bas[a[i]]].insert(b[i]);
}
else{
if(a[i][0]>='a')bas[a[i]]=bas[b[i]];
mp[bas[b[i]]].insert(a[i]);
}
}
}
}
for(auto u : mp){
int curr=0;
for(auto k : u.s){
if(k.size()==1 && k[0]<'a') curr++;
}
if(curr>1) {cout<<"NE\n";return;}
}
cout << "DA\n";
return;
}
int32_t main() {
// freopen("hayfeast.in", "r", stdin);
// freopen("hayfeast.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
int t=1;
// cin >> t;
while (t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Incorrect |
5 ms |
1116 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |