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>
using namespace std;
map<string,vector<string>>mp;
map<string,string>par;
string get(string a){return (par.find(a)!=par.end()?par[a]=get(par[a]):a);}
void unite(string a,string b){
a=get(a);b=get(b);
if(a==b)return;
for(auto j:mp[b])mp[a].push_back(j);
mp[a].push_back(b);
mp[b].clear();par[b]=a;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int x;cin>>x;
string a[x],b[x];
for(int i=0;i<x;i++)cin>>a[i];
for(int i=0;i<x;i++)cin>>b[i],unite(a[i],b[i]);
for(auto [i,r]:mp){
int c=(i[0]>='0'&&i[0]<='9');
for(auto j:r)
if(j[0]>='0'&&j[0]<='9')c++;
if(c>1){
cout<<"NE";return 0;
}
}
cout<<"DA";
return 0;
}
# | 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... |