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;
int MAX_N=100000;
map<string, string>p;
map<string, int>sz;
string Find(string i)
{
if(p[i]==i)
{
return i;
}
return p[i]=Find(p[i]);
}
bool Union(string a, string b)
{
a=Find(a);
b=Find(b);
if(isdigit(a[0]) && isdigit(b[0]))
{
if(a!=b)
return false;
else
return 1;
}
if(isdigit(a[0]))
{
p[b]=a;
sz[a]+=sz[b];
return 1;
}
if(isdigit(b[0]))
{
p[a]=b;
sz[b]+=sz[a];
return 1;
}
if(a!=b)
{
if(sz[a]>sz[b])
{
swap(a, b);
}
p[a]=b;
sz[b]+=sz[a];
}
return 1;
}
int main()
{
int n;
cin>>n;
string a[n], b[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
p[a[i]]=a[i];
sz[a[i]]=1;
}
for(int i=0; i<n; i++)
{
cin>>b[i];
p[b[i]]=b[i];
sz[a[i]]=1;
}
bool kiki=0;
for(int i=0; i<n; i++)
{
if(!Union(a[i], b[i]))
{
kiki=1;
}
}
if(kiki)
{
cout<<"NE";
return 0;
}
else
{
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... |