#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define endl "\n"
#define Sara ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod=998244353;
const double PI=acos(-1);
map<string,bool>vs;
ll cntd=0,cnta=0;
map<string,vector<string>>mp;
set<string>st;
void dfs(string node)
{
vs[node]=1;
if(isdigit(node[0]))
st.insert(node);
for(auto i:mp[node])
{
if(!vs[i])
{
dfs(i);
}
}
}
int main()
{
//freopen("input.in","r",stdin);
Sara
int n;
cin>>n;
vector<string>a(n),b(n);
bool valid=1;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
for(int i=0; i<n; i++)
{
cin>>b[i];
}
for(int i=0; i<n; i++)
{
mp[a[i]].push_back(b[i]);
mp[b[i]].push_back(a[i]);
}
for(int i=0; i<n; i++)
{
dfs(a[i]);
if(st.size()>1){
valid=0;
break;
}
st.clear();
}
if(!valid)
cout<<"NE"<<endl;
else
cout<<"DA"<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
628 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
4 ms |
984 KB |
Output is correct |
4 |
Correct |
4 ms |
1064 KB |
Output is correct |
5 |
Correct |
9 ms |
1228 KB |
Output is correct |
6 |
Correct |
5 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
3212 KB |
Output is correct |
2 |
Correct |
72 ms |
5776 KB |
Output is correct |
3 |
Correct |
39 ms |
7496 KB |
Output is correct |
4 |
Correct |
69 ms |
9988 KB |
Output is correct |
5 |
Correct |
265 ms |
15648 KB |
Output is correct |
6 |
Correct |
216 ms |
11716 KB |
Output is correct |