#include <stdio.h> #include <stdlib.h> typedef struct treenode{ struct treenode *left; struct treenode *right; int v; int flag; }tree; tree insert(tree t,int v){ if(!t){ t=newnode(v); }else{ if(v>t->v){ t->right=insert(t->right,v); } else{ t->left=insert(t->left,v); } } return t; } int check(tree t,int v){ if(t->flag){ if(v<t->v)return check(t->left,v);//如果当前访问完 则访问t的左子树 else if(v>t->v) return check(t->right,v);//访问右子树 else return 0; }else{ if(v==t->v){ t->flag=1;//表示访问完成 return 1; } else{ return 0; } } } int judge(tree t,int n){ int i;v,flag=0; scanf("%d",&v); if(v!=t->v)flag=1; else t->flag=1; for(i=1;i<n;i++){ scanf("%d",&v); if(!flag&&!check(t,v))flag=1; } if(flag)return 0; else return 1; } void reset(tree t){ if(t->left)reset(t->left); if(t->right)reset(t->right); t->flag=0; } void freetree(tree t){ if(t->left)reset(t->left); if(t->right)reset(t->right); free(t); } tree newnode(int V){ tree t=(tree)malloc(sizeof(struct treenode));//创造节点并初始化 t->v=V; t->right=t->left=NULL; t->flag=0;//表示没被访问过为零 return t; } tree maketree(int n){ tree t; int i,v; scanf("%d",&v); t=newnode(v);// 只有一个节点 for(i=0;i<n;i++){ scanf("%d",v); t=insert(t,v); } return t; } int main(){ int n,l,i; tree t; scanf("%d",&n); while(n){ scaanf("%d",&l); t=maketree(n); for(i=0;i<l;i++){ if(judge(t,n)){ printf("yes\n"); } else{ printf("no\n"); } resetT(t); } freetree(t); scanf("%d",&n); } return 0; }