#include <iostream>
#include <fstream>
using namespace std;
int sum[100];
struct node
{
int data;
node *left,*right;
};
void create(node *&t,int k)
{
if(t==NULL)
{
t=new node;
t->data=k;
t->left=NULL;
t->right=NULL;
}
cin>>k;
if(k!=-1)
create(t->right,k);
cin>>k;
if(k!=-1)
create(t->left,k);
}
int max(int a ,int b)
{
if(a>b)
return a;
return b;
}
bool identicle(node *t,node *p)
{
if(t==NULL&&p==NULL)
return true;
if(t->data==p->data&&identicle(t->left,p->left)&&identicle(t->right,p->right))
return true;
return false;
}
bool fun(node *t,node *p)
{
if(p==NULL)
return true;
if(t==NULL)
return false;
return(fun(t->left,p)||fun(t->right,p)||identicle(t,p));
return false;
}
int main()
{
int k;
node *t;
t=NULL;
int a,a1;
cin>>a;
create(t,a);
cout<<"enter for 2nd tree\n";
cin>>a;
node *p=NULL;
create(p,a);
cout<<"trees create compeleted\n";
if(fun(t,p))
cout<<"yes";
else
cout<<"no";
return 0;
}
#include <fstream>
using namespace std;
int sum[100];
struct node
{
int data;
node *left,*right;
};
void create(node *&t,int k)
{
if(t==NULL)
{
t=new node;
t->data=k;
t->left=NULL;
t->right=NULL;
}
cin>>k;
if(k!=-1)
create(t->right,k);
cin>>k;
if(k!=-1)
create(t->left,k);
}
int max(int a ,int b)
{
if(a>b)
return a;
return b;
}
bool identicle(node *t,node *p)
{
if(t==NULL&&p==NULL)
return true;
if(t->data==p->data&&identicle(t->left,p->left)&&identicle(t->right,p->right))
return true;
return false;
}
bool fun(node *t,node *p)
{
if(p==NULL)
return true;
if(t==NULL)
return false;
return(fun(t->left,p)||fun(t->right,p)||identicle(t,p));
return false;
}
int main()
{
int k;
node *t;
t=NULL;
int a,a1;
cin>>a;
create(t,a);
cout<<"enter for 2nd tree\n";
cin>>a;
node *p=NULL;
create(p,a);
cout<<"trees create compeleted\n";
if(fun(t,p))
cout<<"yes";
else
cout<<"no";
return 0;
}