This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll , ll> llll;
typedef std::string str;
std::vector<ll> ar;
std::map<str , str> par , plt;
std::map<str , ll> siz;
str fin(str crt){
if(crt == par[crt]){
return crt;
}
return par[crt] = fin(par[crt]);
}
void mrg(str x , str y){
x = fin(x);y = fin(y);
if(x != y){
if(siz[x] < siz[y]){
swap(x , y);
}
par[y] = x;
siz[x] += siz[y];
}
}
ll n;
void solve(){
std::cin >> n;
str h[n][2];
for(ll i = 0;n>i;i++){
std::cin >> h[i][0];
par[h[i][0]] = h[i][0];
siz[h[i][0]] = 1;
}
for(ll i = 0;n>i;i++){
std::cin >> h[i][1];
par[h[i][1]] = h[i][1];
siz[h[i][1]] = 1;
}
for(ll i = 0;n>i;i++){
mrg(h[i][1] , h[i][0]);
}
for(ll i = 0;n>i;i++){
if(h[i][0][0] >= '0' && h[i][0][0] <= '9'){
str o = fin(h[i][0]);
if(plt[o].size() == 0){
plt[o] = h[i][0];
}
else if(plt[o] != h[i][0]){
std::cout << "NE\n";
return;
}
}
if(h[i][1][0] >= '0' && h[i][1][0] <= '9'){
str o = fin(h[i][1]);
if(plt[o].size() == 0){
plt[o] = h[i][1];
}
else if(plt[o] != h[i][1]){
std::cout << "NE\n";
return;
}
}
}
std::cout << "DA\n";
}
int main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t = 1;
//std::cin >> t;
while(t--){
solve();
}
}
# | 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... |