This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// KALAM
# include<bits/stdc++.h>
using namespace std;
const int N = 100000 + 77;
int n , P[N];
string X[N] , Y[N];
vector < string > V;
inline int GetId(string T) {return lower_bound(V.begin() , V.end() , T) - V.begin() + 1;}
int Find(int x) {return P[x] <= 0 ? x : (P[x] = Find(P[x]));}
inline void Merge(int v , int u) {
v = Find(v);
u = Find(u);
if(v == u)
return ;
P[v] += P[u];
P[u] = v;
}
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n;
for(int i = 1;i <= n;++ i)
cin >> X[i] , V.push_back(X[i]);
for(int i = 1;i <= n;++ i)
cin >> Y[i] , V.push_back(Y[i]);
sort(V.begin() , V.end());
V.resize(unique(V.begin() , V.end()) - V.begin());
for(string S : V)
if(S[0] <= '9' && S[0] >= '0')
-- P[GetId(S)];
for(int i = 1;i <= n;++ i)
Merge(GetId(X[i]) , GetId(Y[i]));
for(int i = 1;i <= n;++ i)
if(P[i] < - 1)
return ! printf("NE\n");
printf("DA\n");
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... |