题目描述
Problem Description
Sukenu-kun has a tree \( T \) with \( n+1 \) vertices. Each vertex in this tree \( T \) is labeled with an integer, specifically \( 1, 2, \ldots, n+1 \). The tree \( T \) has \( n \) edges, where the \( i \)-th edge connects the vertex labeled \( i \) and the vertex labeled \( v_i \).
Nusuke-kun, taking advantage of Sukenu-kun's momentary distraction, played a prank on the tree \( T \) as follows:
- He removed one of the vertices with degree \( 1 \) from the tree \( T \) and hid it.
- He erased all the integers written on the remaining \( n \) vertices.
- He wrote new integers \( 1, 2, \ldots, n \) on each of the remaining \( n \) vertices.
Let's call the tree after Nusuke-kun's prank \( T' \). The tree \( T' \) has \( n-1 \) edges, where the \( i \)-th edge connects the vertex labeled \( i \) and the vertex labeled \( u_i \).
Noticing Nusuke-kun's prank, Sukenu-kun wants to guess the integer written on the vertex that Nusuke-kun hid. Find all possible integers that could be written on that hidden vertex and output them in ascending order.
Input Format
The input is given from the standard input in the following format:
\( n \) \( v_1 \) \( v_2 \) \( \dots \) \( v_n \) \( u_1 \) \( u_2 \) \( \dots \) \( u_{n-1} \)
Output Format
Output all possible integers that could be written on the vertex hidden by Nusuke-kun in ascending order, separated by spaces, on one line.
Sample Input and Output
Sample Input #1
10
2 9 2 2 2 2 6 7 10 11
2 3 4 10 4 5 4 4 4
Sample Output #1
8 11
Sample Input #2
5
6 1 1 1 1
5 5 5 5 5
Sample Output #2
2 3 4 5 6
Sample Input #3
5
4 3 4 5 6
2 3 4 5
Sample Output #3
1
Notes/Hints
Constraints
- \( 2 \leq n \leq 2 \times 10^5 \)
- For \( i = 1, 2, \ldots, n \), \( 1 \leq v_i \leq n+1 \)
- For \( i = 1, 2, \ldots, n-1 \), \( 1 \leq u_i \leq n \)
- \( T \) (the graph consisting of edges \( (1, v_1), (2, v_2), \ldots, (n, v_n) \)) is a tree.
- \( T' \) (the graph consisting of edges \( (1, u_1), (2, u_2), \ldots, (n-1, u_{n-1}) \)) is a tree.
- There is at least one possible vertex that Nusuke-kun could have hidden.
- All inputs are integers.
Sample Explanation 1
Vertices with degree \( 1 \) are those labeled \( 1, 3, 4, 5, 8, 11 \). For example, if the vertex labeled \( 11 \) is hidden, the tree \( T' \) can be matched by reassigning the integers as follows. Similarly, if the vertex labeled \( 8 \) is hidden, the tree \( T' \) can also be matched. Since no other vertices can be hidden to match the tree \( T' \), the answer is 8 11 in ascending order.
Sample Explanation 2
Vertices with degree \( 1 \) are those labeled \( 2, 3, 4, 5, 6 \). Any of these can be hidden and the tree \( T' \) can be matched by reassigning the integers, so all of these should be output.
Sample Explanation 3
Sukenu-kun can deduce that the hidden vertex must be labeled \( 1 \).
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分