# 03-树1 树的同构 (25 分)

### 输入样例1（对应图1）：

8
A 1 2
B 3 4
C 5 -
D - -
E 6 -
G 7 -
F - -
H - -
8
G - 4
B 7 6
F - -
A 5 1
H - -
C 0 -
D - -
E 2 -

### 输出样例1:

Yes

### 输入样例2（对应图2）：

8 B 5 7 F - - A 0 3 C 6 - H - - D - - G 4 - E 1 - 8 D 6 - B 5 - E - - H - - C 0 2 G - 3 F - - A 1 4

### 输出样例2:

No
#include<cstdio>
const int maxn = 11;
int countsa[maxn];
int countsb[maxn];

int main(){
int n;
scanf("%d",&n);
for (int i = 0; i < n; i++){
int add = 2;
char a,b,c;
scanf("%*c");
scanf("%c %c %c",&a,&b,&c);
if(b == ‘-‘)
{
}
if(c == ‘-‘)
{
}
}
scanf("%d",&n);
for(int i = 0; i < n; i++){
int add = 2;
char a,b,c;
scanf("%*c");
scanf("%c %c %c",&a,&b,&c);
if(b == ‘-‘)
{
}
if(c == ‘-‘)
{
}
}
if(n==1)
{
printf("No\n");
}
else
{
int i;
for(i = 0; i < n; i++)
{
if(countsa[i] != countsb[i])
{
printf("No\n");
break;
}
}
if(i == n)printf("Yes\n");
}

return 0;
}

#include<cstdio>
#include<cstdlib>
#include<cstring>
const int maxn = 11;

int *solve(int n);
//bool isSame(int *a, int *b, int n);

int main()
{
int n;
scanf("%d",&n);
int *a = solve(n);
scanf("%d",&n);
int *b = solve(n);

if (1 == n)
{
printf("No\n");
}
else
{
int i = 0;
for (; i < n; i++)
{
if (a[i] != b[i])
{
printf("No\n");
break;
}
}
if (i == n)
{
printf("Yes\n");
}
}

#if 0
if (isSame(a,b,n))
{
printf("Yes\n");
}
else
{
printf("No\n");
}
#endif
return 0;
}

int *solve(int n)
{
int *arr;
arr = (int *)malloc(n * sizeof(int));
memset(arr,0,sizeof(arr) * n);

char a,b,c;
for (int i = 0; i < n; i++)
{
int add = 2;
scanf("%*c");
scanf("%c %c %c",&a,&b,&c);
if (b == ‘-‘)
{
}
if (c == ‘-‘)
{
}
arr[a - ‘A‘] += add;
}
return arr;
}

bool isSame(int *a, int *b, int n)
{
if (1 == n)
{
return false;
}
bool bRet = false;
int i = 0;
for (i = 0; i < n; i++)
{
if (a[i] != b[i])
{
break;
}
}

if (i == n)
{
bRet = true;
}

return bRet;
}