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 n,flag,cnt,size[100005],dad[100005];
string str,val[100005],kendi[100005];
map<string,int> yer;
vector<string> v;
void uni(int root_a,int root_b){
if(size[root_a]<size[root_b]){
dad[root_a]=dad[root_b];
size[root_b]+=size[root_a];
}
else{
dad[root_b]=dad[root_b];
size[root_a]+=size[root_b];
}
}
int root(int i){
while(dad[i]!=i){
dad[i]=dad[dad[i]];
i=dad[i];
}
return i;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i=0;i<n;i++){
cin >> str;
v.push_back(str);
if(yer.find(str)==yer.end()){
yer[str]=cnt;
kendi[cnt]=str;
val[cnt]=str;
size[cnt]=1;
dad[cnt]=cnt++;
}
}
for(int i=0;i<n;i++){
cin >> str;
if(yer.find(str)==yer.end()){
yer[str]=cnt;
kendi[cnt]=str;
val[cnt]=str;
size[cnt]=1;
dad[cnt]=cnt++;
}
if(str!=v[i]){
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
str.find("6")!=-1 || str.find("7")!=-1 || str.find("8")!=-1 || str.find("9")!=-1){
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1)
flag=1;
else{
int baba_v=root(yer[v[i]]);
if(val[baba_v]!=kendi[baba_v] && val[baba_v]!=str)
flag=1;
else
val[baba_v]=str;
}
}
else{
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1){
int baba_str=root(yer[str]);
if(val[baba_str]!=kendi[baba_str] && val[baba_str]!=v[i])
flag=1;
else
val[baba_str]=v[i];
}
else{
int baba_str=root(yer[str]);
int baba_v=root(yer[v[i]]);
if(baba_v!=baba_str){
if(val[baba_v]!=kendi[baba_v] && val[baba_str]!=kendi[baba_str] && val[baba_v]!=val[baba_str])
flag=1;
else{
if(val[baba_v]==kendi[baba_v] && val[baba_str]==kendi[baba_str])
uni(baba_v,baba_str);
else{
if(size[baba_v]<size[baba_str] && val[baba_v]!=kendi[baba_v])
val[baba_str]=val[baba_v];
else if(size[baba_str]<size[baba_v] && val[baba_str]!=kendi[baba_str])
val[baba_v]=val[baba_str];
uni(baba_v,baba_str);
}
}
}
}
}
}
}
printf("%s\n",flag ? "NE" : "DA");
return 0;
}
Compilation message (stderr)
zamjena.cpp: In function 'int main()':
zamjena.cpp:36:25: warning: operation on 'cnt' may be undefined [-Wsequence-point]
dad[cnt]=cnt++;
~~~^~
zamjena.cpp:46:25: warning: operation on 'cnt' may be undefined [-Wsequence-point]
dad[cnt]=cnt++;
~~~^~
zamjena.cpp:50:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
~~~~~~~~~~~~~^~~~
zamjena.cpp:50:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
~~~~~~~~~~~~~^~~~
zamjena.cpp:50:71: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
~~~~~~~~~~~~~^~~~
zamjena.cpp:50:92: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
~~~~~~~~~~~~~^~~~
zamjena.cpp:50:113: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
~~~~~~~~~~~~~^~~~
zamjena.cpp:50:134: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(str.find("0")!=-1 || str.find("1")!=-1 || str.find("2")!=-1 || str.find("3")!=-1 || str.find("4")!=-1 || str.find("5")!=-1 ||
~~~~~~~~~~~~~^~~~
zamjena.cpp:51:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
str.find("6")!=-1 || str.find("7")!=-1 || str.find("8")!=-1 || str.find("9")!=-1){
~~~~~~~~~~~~~^~~~
zamjena.cpp:51:55: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
str.find("6")!=-1 || str.find("7")!=-1 || str.find("8")!=-1 || str.find("9")!=-1){
~~~~~~~~~~~~~^~~~
zamjena.cpp:51:76: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
str.find("6")!=-1 || str.find("7")!=-1 || str.find("8")!=-1 || str.find("9")!=-1){
~~~~~~~~~~~~~^~~~
zamjena.cpp:51:97: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
str.find("6")!=-1 || str.find("7")!=-1 || str.find("8")!=-1 || str.find("9")!=-1){
~~~~~~~~~~~~~^~~~
zamjena.cpp:53:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:53:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:53:78: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:53:100: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:53:122: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:53:144: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:54:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1)
~~~~~~~~~~~~~~^~~~
zamjena.cpp:54:61: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1)
~~~~~~~~~~~~~~^~~~
zamjena.cpp:54:83: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1)
~~~~~~~~~~~~~~^~~~
zamjena.cpp:54:105: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1)
~~~~~~~~~~~~~~^~~~
zamjena.cpp:68:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:68:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:68:78: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:68:100: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:68:122: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:68:144: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(v[i].find("0")!=-1 || v[i].find("1")!=-1 || v[i].find("2")!=-1 || v[i].find("3")!=-1 || v[i].find("4")!=-1 || v[i].find("5")!=-1 ||
~~~~~~~~~~~~~~^~~~
zamjena.cpp:69:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1){
~~~~~~~~~~~~~~^~~~
zamjena.cpp:69:61: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1){
~~~~~~~~~~~~~~^~~~
zamjena.cpp:69:83: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1){
~~~~~~~~~~~~~~^~~~
zamjena.cpp:69:105: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
v[i].find("6")!=-1 || v[i].find("7")!=-1 || v[i].find("8")!=-1 || v[i].find("9")!=-1){
~~~~~~~~~~~~~~^~~~
# | 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... |