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;
typedef long long ll;
#define endl '\n'
map <string,vector<string>> adj;
map <string,bool> vis;
string curNum = "-1";
bool isNum(string s){
for(auto i : s){
if(i < '0' || i > '9') return 0;
}
return 1;
}
bool valid = 1;
void dfs(string node){
vis[node] = 1;
if(isNum(node) && curNum == "-1"){
curNum = node;
}
for(auto ch : adj[node]){
if(!isNum(ch) || curNum == ch || curNum == "-1"){
if(!vis[ch]) dfs(ch);
}
else valid = 0;
}
}
void solve(){
int n;
cin>>n;
vector <string> v1(n);
vector <string> v2(n);
for(auto &i:v1) cin>>i;
for(auto &i:v2) cin>>i;
for(int i=0;i<n;i++){
adj[v1[i]].push_back(v2[i]);
adj[v2[i]].push_back(v1[i]);
}
for(auto i : v1){
if(!vis[i]) dfs(i);
if(!valid){
cout<<"NE"<<endl;
return;
}
valid = 1;
curNum = "-1";
}
for(auto i : v2){
if(!vis[i]) dfs(i);
if(!valid){
cout<<"NE"<<endl;
return;
}
curNum = "-1";
}
cout<<"DA"<<endl;
}
int main()
{
int t=1;
// cin>>t;
while(t--){
solve();
}
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... |