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;
#define finish(x){cout << x << endl; exit(0);}
#define ll long long
int n;
vector <string> a, b;
map <string, string> p;
bool num(string &x){
return '0' <= x[0] && x[0] <= '9';
}
string find(string x){
if(p[x] == x) return x;
return p[x] = find(p[x]);
}
void merge(string a, string b){
a = find(a);
b = find(b);
p[a] = b;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(n);
for(auto &i : a) cin >> i;
b.resize(n);
for(auto &i : b) cin >> i;
for(int i = 0 ; i < n ; i++){
p[a[i]] = a[i];
p[b[i]] = b[i];
}
for(int i = 0 ; i < n ; i++){
merge(a[i], b[i]);
}
set <string> nums;
for(int i = 0 ; i < n ; i++){
if(num(a[i])) nums.insert(a[i]);
if(num(b[i])) nums.insert(b[i]);
}
set <string> all;
for(auto &i : nums) all.insert(find(i));
if(all.size() != nums.size()) cout << "NE\n";
else cout << "DA\n";
}
# | 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... |