# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472354 | Ahmed57 | Zamjena (COCI18_zamjena) | C++14 | 169 ms | 15104 KiB |
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>>adj;
map<string,bool>vis;
long long a=0;
bool is(string s){
for(int i=0;i<s.size();i++){
if(s[i]<'0'||s[i]>'9')
return false;
}
return true;
}
void dfs(string n){
if(is(n))
a++;
vis[n]=true;
for(auto i:adj[n])
if(!vis[i])
dfs(i);
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n;
cin>>n;
vector<string>arr(n);
vector<string>aee(n);
for(int i=0;i<n;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++){
cin>>aee[i];
adj[aee[i]].push_back(arr[i]);
adj[arr[i]].push_back(aee[i]);
}
for(int i=0;i<n;i++){
a=0;
if(is(arr[i])&&is(aee[i])){
if(arr[i]!=aee[i]){
cout<<"NE"<<endl;
return 0;
}
}
else{
if(is(arr[i])&&!vis[aee[i]])dfs(aee[i]);
else if(is(aee[i])&&!vis[arr[i]])dfs(arr[i]);
if(a>1){
cout<<"NE"<<endl;
return 0;
}
}
}
cout<<"DA"<<endl;
}
Compilation message (stderr)
# | 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... |