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;
map<string, string> parent;
map<string, int> sz;
string Find(string x) {
if (parent[x]==x)
return x;
return parent[x]=Find(parent[x]);
}
bool Union(string a, string b) {
a=Find(a), b=Find(b);
if (a[0]-'0'<=9&&b[0]-'0'<=9)
return a==b;
if (a[0]-'0'<=9) {
parent[b]=a;
sz[a]+=sz[b];
return 1;
}
if (b[0]-'0'<=9) {
parent[a]=b;
sz[b]+=sz[a];
return 1;
}
if (a==b) return 1;
if (sz[a]<sz[b])
swap(a,b);
sz[a]+=sz[b];
parent[b]=a;
return 1;
}
int main()
{
int n;
cin >> n;
string a[n], b[n];
for (int i=0;i<n;i++) {
cin >> a[i];
parent[a[i]]=a[i];
sz[a[i]]=1;
}
for (int i=0;i<n;i++) {
cin >> b[i];
parent[b[i]]=b[i];
sz[b[i]]=1;
}
for (int i=0;i<n;i++) {
if (!Union(a[i], b[i])) {
cout << "NE";
return 0;
}
}
cout << "DA";
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... |