#include<cstdio>
using namespace std;
struct node{
int left;
int right;
int root;
char id;
}tree[20],bt[20];
int main()
{
int n;
char l,r;
char c;
scanf("%d",&n);
for(int i=0;i<n;i++){
tree[i].left = -1;
tree[i].right = -1;
tree[i].root = -1;
bt[i].left = -1;
bt[i].right = -1;
bt[i].root = -1;
}
for(int i=0;i<n;i++){
scanf("\n%c %c %c",&c,&l,&r);
tree[i].id = c;
if(l!='-') {
tree[i].left=l-'0';
tree[l-'0'].root = 0;
}
if(r!='-')
{
tree[i].right = r-'0';
tree[r-'0'].root = 0;
}
}
scanf("\n%d",&n);
for(int i=0;i<n;i++){
scanf("\n%c %c %c",&c,&l,&r);
bt[i].id = c;
if(l!='-') {
bt[i].left=l-'0';
bt[l-'0'].root = 0;
}
if(r!='-')
{
bt[i].right = r-'0';
bt[r-'0'].root = 0;
}
}
int count = 0;
if(n>1){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(tree[i].id==bt[j].id){
int l1 =tree[i].left;
int r1 =tree[i].right;
int l2 =bt[j].left;
int r2 =bt[j].right;
if(tree[l1].id!=bt[l2].id&&tree[l1].id!=bt[r2].id) count=1;
if(tree[r1].id!=bt[l2].id&&tree[r2].id!=bt[r2].id) count=1;
}
}
}
}else{
if(tree[0].id!=bt[0].id) count=1;
}
if(count) printf("No");
else printf("Yes");
return 0;
}
03-树1 树的同构
最新推荐文章于 2024-05-28 21:54:22 发布