# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464635 | ahmedfouadnew | Zamjena (COCI18_zamjena) | C++17 | 74 ms | 10956 KiB |
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 int long long
#define pb push_back
const int mod=1e9+7;
map<string,string>mp;
int n;
string s[50001];
string s2[50001];
int sz[100001];
int par[100001];
int num[100001];
vector<pair<string,int> >vv;
int its(string sss)
{
int ret=0;
for(int i=0;i<sss.size();i++)
{
ret*=10;
ret+=sss[i]-'0';
}
return ret;
}
int findp(int u)
{
if(par[u]==u)
return u;
return par[u]=findp(par[u]);
}
void join(int u,int v)
{
u=findp(u);
v=findp(v);
if(u==v) return;
if(num[u]&&num[v]&&(num[u]!=num[v]))
{
puts("NE");
exit(0);
}
if(sz[u]<sz[v]) swap(u,v);
par[v]=u;
sz[u]+=sz[v];
num[u]=num[u]|num[v];
return;
}
signed main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>s[i];
sz[i]=1;
par[i]=i;
if(s[i][0]<='9'&&s[i][0]>='1')
num[i]=its(s[i]);
}
for(int i=0;i<n;i++)
{
cin>>s2[i];
par[n+i]=n+i;
sz[n+i]=1;
if(s2[i][0]<='9'&&s2[i][0]>='1')
num[n+i]=its(s2[i]);
}
for(int i=0;i<n;i++)
{
vv.pb({s[i],i});
vv.pb({s2[i],n+i});
join(i,i+n);
}
sort(vv.begin(),vv.end());
for(int i=1;i<vv.size();i++)
{
if(vv[i].first[0]<='9'&&vv[i].first[0]>='1') continue;
if(vv[i].first==vv[i-1].first)
{
join(vv[i].second,vv[i-1].second);
}
}
puts("DA");
return 0;
}
Compilation message (stderr)
# | 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... |