Address: https://pintia.cn/problem-sets/15/problems/711
Solution:
Determine whether the tree is homogeneous and whether the children (or parent nodes) of the nodes that store the same information are consistent;
We recommend that you use struct arrays to store trees. input node subscripts are 0 => n-1.
Root Node judgment: Based on the input information of the question, the left child and the Right child are the node information. Therefore, the node that has not appeared in the Child Information is the root node.
Sample Analysis: To determine the parent node of a node.
The following table is obtained based on the input information of the two shards.
Left |
A |
B |
C |
D |
E |
G |
G |
H |
Index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Value |
-1 |
0 |
0 |
1 |
1 |
2 |
4 |
5 |
|
A |
B |
C |
D |
E |
G |
G |
H |
Index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Value |
-1 |
0 |
0 |
1 |
1 |
2 |
4 |
5 |
For each node in the two trees, their parent nodes are consistent. They are homogeneous. If there is an inconsistency, they are considered non-homogeneous.
For the following two regions
|
G |
B |
F |
A |
H |
C |
D |
E |
Index |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
Value |
1 |
3 |
7 |
-1 |
0 |
3 |
|
|
Value |
5 |
3 |
6 |
-1 |
0 |
3 |
|
|
7-3 tree homogeneity (25 points)