#include <cstdio>
using namespace std;
struct tree {
int data;
tree *l, *r;
tree() {
l=r=NULL;
}
};
int x;
bool f;
tree *insert(tree *root) {
if(!root) {
root=new tree;
root->data=x;
}
else if(x<root->data)
root->l=insert(root->l);
else root->r=insert(root->r);
return root;
}
void judge(tree *root1, tree *root2) {
if(root1&&root2) {
if(root1->data!=root2->data) {
f=0;
return ;
}
judge(root1->l,root2->l);
judge(root1->r,root2->r);
}
}
int main() {
int n, m;
while(~scanf("%d", &n)) {
if(!n) break;
scanf("%d", &m);
tree *root1=new tree;
scanf("%d", &root1->data);
for(int i=1;i<n;i++) {
scanf("%d", &x);
root1=insert(root1);
}
while(m--) {
f=1;
tree *root2=new tree;
scanf("%d", &root2->data);
for(int i=1;i<n;i++) {
scanf("%d", &x);
root2=insert(root2);
}
judge(root1,root2);
if(f) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
数据结构实验之查找一:二叉排序树
最新推荐文章于 2020-12-02 08:55:19 发布