The homogeneous structure of the root tree means that the two trees have the same shape and the subtree can be rotated. Therefore, when the number of subnodes of the subtree is the same, the homogeneous structure can be determined.
You do not need to create a result. You only need to use the DFS to backtrack when '1' is encountered. Opening an array hash [I] = J indicates that the number of subnodes is I (including the number of subnodes) the node number is J.
0 Ms no pressure
Int hash [801]; // hash [I] = J indicates that the node with the subnode number being I (including itself) is J int get1 () {int n = 1; char C; while (C = getchar () = '0') {n + = get1 (); // The current node continues until it returns to '1' and uses Recursive Backtracking} hash [N] ++; return n ;}int get2 () {int n = 1; char C; while (C = getchar () = '0') {n + = get2 ();} hash [N] --; return n ;}int main () {int N; scanf ("% d \ n", & N); While (n --) {memset (hash, 0, sizeof (hash); get1 (); get2 (); bool OK = 1; int I; for (I = 1; I <801 & OK; I ++ ){ If (hash [I]! = 0) OK = 0;} If (OK) puts ("same"); else puts ("different");} return 0 ;}