# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1084336 | BlueGlaucus1 | Zamjena (COCI18_zamjena) | C++17 | 0 ms | 0 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 <iostream>
#include <string>
#include <map>
using namespace std;
map<string, vector<string> > con;
map<string, bool> visited;
int dfs(string s){
int curr_val = 0;
if(isdigit(s[0])){
curr_val = stoi(s);
}
visited[s] = 1;
for(int i = 0; i <con[s].size();i++){
string val = con[s][i];
if(visited[val]){
continue;
}
int cor = dfs(val);
if(cor == -1){
return -1;
}
else if (cor ==0){
continue;
}
else if (curr_val==0){
curr_val = cor;
}else if (curr_val!=cor){
return -1;
}
}
return curr_val;
}
int main(){
int n; cin >> n;
string arr[n];
string brr[n];
for(int i =0; i <n;i++){
cin >> arr[i];
}
for(int i =0; i <n;i++){
cin >> brr[i];
}
for(int i =0; i <n;i++){
con[arr[i]].push_back(brr[i]);
con[brr[i]].push_back(arr[i]);
}
for(int i = 0; i <n;i++){
if(!visited[arr[i]]){
int g = dfs(arr[i]);
if(g==-1){
cout <<"NE";
return 0;
}
}
}
cout << "DA"<<'\n';
return 0;
}