1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 using namespace std;
6 struct node{
7 char val;
8 int left;
9 int right;
10 }t1[22],t2[22];
11 int in[22];
12 int n;
13 int build(struct node e[])
14 {
15 string a,b,c;
16 scanf("%d",&n);
17 // cout<<"n="<<n<<endl;
18 if(n==0)
19 {
20 // cout<<"lala"<<endl;
21 return -1;
22 }
23
24 memset(in,0,sizeof(in));
25 for(int i=0;i<n;i++)
26 {
27 cin>>a>>b>>c;
28 e[i].val=a[0];
29 if(b[0]!='-')
30 {
31 e[i].left=b[0]-'0';
32 in[e[i].left]=1;
33 }
34 else
35 e[i].left=-1;
36 if(c[0]!='-')
37 {
38 e[i].right=c[0]-'0';
39 in[e[i].right]=1;
40 }
41 else
42 e[i].right=-1;
43 }
44 for(int i=0;i<n;i++)
45 {
46 if(!in[i])
47 return i;
48 }
49 }
50 int judge(int r1,int r2)
51 {
52 if(r1==-1&&r2==-1)
53 return 1;
54 if((r1==-1&&r2!=-1)||(r1!=-1&&r2==-1))
55 return 0;
56 if(t1[r1].val!=t2[r2].val)
57 return 0;
58 if(t1[r1].left==-1&&t2[r2].left==-1)
59 return judge(t1[r1].right,t2[r2].right);
60 else
61 {
62 if(t1[t1[r1].left].val==t2[t2[r2].left].val)
63 return judge(t1[r1].left,t2[r2].left)&&judge(t1[r1].right,t2[r2].right);
64 else
65 return judge(t1[r1].left,t2[r2].right)&&judge(t1[r1].right,t2[r2].left);
66 }
67 }
68 int main()
69 {
70 int r1=build(t1);
71 //cout<<"r1="<<r1<<endl;
72 int r2=build(t2);
73 // cout<<r1<<" "<<r2<<endl;
74 if(judge(r1,r2))
75 cout<<"Yes"<<endl;
76 else
77 cout<<"No"<<endl;
78 }
1 #include <bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4 struct node{
5 int l,r,x;
6 }a[20],b[20];
7 map<int,int> mp;
8 int n,m;
9 char s1[10],s2[10],s3[10];
10 bool judge(int x1,int x2){
11 if(a[x1].x!=b[x2].x) return 0;
12 if(a[a[x1].l].x==b[b[x2].l].x&&a[a[x1].r].x==b[b[x2].r].x)
13 return 1;
14 if(a[a[x1].l].x==b[b[x2].r].x&&a[a[x1].r].x==b[b[x2].l].x)
15 return 1;
16 //cout<<x1<<" "<<x2<<endl;
17 return 0;
18 }
19 int main(void){
20 cin>>n;
21 for(int i=0;i<n;i++){
22 scanf("%s%s%s",s1,s2,s3);
23 a[i].x=s1[0];
24 a[i].l=(s2[0]=='-'?15:s2[0]-'0');
25 a[i].r=(s3[0]=='-'?15:s3[0]-'0');
26 }
27 cin>>m;
28 for(int i=0;i<m;i++){
29 scanf("%s%s%s",s1,s2,s3);
30 b[i].x=s1[0];
31 mp[b[i].x]=i;
32 b[i].l=(s2[0]=='-'?15:s2[0]-'0');
33 b[i].r=(s3[0]=='-'?15:s3[0]-'0');
34 }
35 if(n!=m){
36 puts("No");
37 return 0;
38 }
39 bool flag=1;
40 for(int i=0;i<n;i++)
41 if(!judge(i,mp[a[i].x]))
42 flag=0;
43 puts(flag?"Yes":"No");
44 return 0;
45 }