Tree Isomorphism
Two trees, each consisting of N nodes, are provided. These trees are considered isomorphic if they share the same structure.
Specifically, trees A and B are isomorphic if there exists a permutation p = (p_1, ..., p_N) such that node i is the root in tree A if and only if node p_i is the root in tree B. Additionally, node i is the parent of node j in tree A if and only if p_i is the parent of p_j in tree B.
Input
The first line of the input contains a natural number N (1 ≤ N ≤ 10^5). The second and third lines describe the trees. Each line contains N integers a_1, a_2, ..., a_N, where a_i indicates the parent node number for node i, or is 0 if node i is the root.
Output
The output should consist of N numbers representing the permutation p that maps the first tree onto the second. If multiple permutations exist, any valid one can be provided. If the trees are not isomorphic, output a single number -1.