# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151413 | phillip | Zamjena (COCI18_zamjena) | C++14 | 230 ms | 17900 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;
vector<string>s;
map<string,int>name;
int val[100009],vis[100009];
vector<int>v[100009];
void dfs(int x)
{
if(vis[x])return;
vis[x]=1;
for(int i=0;i<v[x].size();i++)
{
int y=v[x][i];
if(val[x]!=val[y]&&val[y]!=-1)
{
cout<<"NE";
exit(0);
}
val[y]=val[x];
dfs(y);
}
}
int mapit(string s)
{
if(s.size()<=3)
{
int x=0,ml=1;
for(int i=s.size()-1;i>=0;i--)
{
if(s[i]-'0'>9)
{
return -1;
}
x+=(s[i]-'0')*ml;
ml*=10;
}
return x;
}
return -1;
}
int n;
string a1[100090],a2[100009];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a1[i];
s.push_back(a1[i]);
}
for(int i=0;i<n;i++)
{
cin>>a2[i];
s.push_back(a2[i]);
}
int nn;
for(int i=0,j=0;i<s.size();i++)
{
if(name[s[i]])continue;
name[s[i]]=j;
val[j]=mapit(s[i]);
j++;
nn=j;
}
for(int i=0;i<n;i++)
{
int x=name[a1[i]],y=name[a2[i]];
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=0;i<nn;i++)
{
if(val[i]==-1)continue;
dfs(i);
}
cout<<"DA";
}
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... |