#include<bits/stdc++.h>
using namespace std;
struct tree
{
int data;
struct tree *lc,*rc;
};
void creat(struct tree *&node,int a)
{
if(node==NULL)
{
node=(struct tree *)malloc(sizeof(struct tree));
node->data=a;
node->lc=node->rc=NULL;
}
else if(a<node->data)
creat(node->lc,a);
else
creat(node->rc,a);
}
int ju(struct tree *t1,struct tree *t2)
{
if(t1==NULL&&t2==NULL)
return 1;
if(t1!=NULL&&t2!=NULL)
if(t1->data==t2->data)
if((ju(t1->lc,t2->lc)&&ju(t1->rc,t2->rc))||(ju(t1->rc,t2->lc)&&ju(t1->lc,t2->rc)))
return 1;
return 0;
}
int main()
{
int n,T;
while(~scanf("%d",&n)&&n)
{
scanf("%d",&T);
struct tree *root=NULL;
for(int i=0; i<n; i++)
{
int t;
scanf("%d",&t);
creat(root,t);
}
while(T--)
{
struct tree *root0=NULL;
for(int i=0; i<n; i++)
{
int t;
scanf("%d",&t);
creat(root0,t);
}
if(ju(root,root0))
printf("Yes\n");
else
printf("No\n");
}
}
}
SDUT3373数据结构实验之查找一:二叉排序树
最新推荐文章于 2019-01-15 09:54:08 发布