7-4 是否同一棵二叉搜索树 （25 分）

### 输入样例:

``````4 2
3 1 4 2
3 4 1 2
3 2 4 1
2 1
2 1
1 2
0``````

### 输出样例:

``````Yes
No
No``````
``````#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100006;
struct node {
int data;
struct node *lc, *rc;
};
struct node *creat(struct node *root, int x )
{
if(root == NULL) {
root = new node;
root -> data = x;
root -> lc = NULL;
root -> rc = NULL;
}
else {
if(x > root -> data)
{
root -> rc = creat(root -> rc, x);
}
else {
root -> lc = creat(root -> lc, x);
}
}
return root;
};

bool ok(struct node *t1, struct node *t2)
{
if(t1 == NULL && t2 == NULL) return 1;
else if(t1 -> data != t2 -> data)
{
return 0;
}
else if(ok(t1->lc,t2->lc) && ok(t1->rc,t2 -> rc)) return 1;
else return 0;
}
int a[55], b[55];
int main()
{
ios::sync_with_stdio(0);
int n,l;
while(cin >> n)
{
if(n == 0) return 0;
cin >> l;
for(int i = 0; i < n; i ++) cin >> a[i];
struct node *t1, *t2;
t1 = NULL; t2 = NULL;
for(int i = 0; i < n; i ++)
{
t1 = creat(t1,a[i]);
}
while(l --)
{
t2 = NULL;
for(int i = 0; i < n; i ++) cin >> b[i];
for(int i = 0; i < n; i ++) t2 = creat(t2,b[i]);
bool f = ok(t1,t2);
if(f) cout << "Yes" << endl;
else cout << "No" << endl;
}
}

return 0;
}``````