The lovely WrongAnswer is very fond of independent set problems. For his thesis defense in CTSC2017, he prepared a paper on independent sets.
One day, WrongAnswer decided he would use this paper to set a question. The question he eventually came up with was:
Subtasks # | Score | Constraints |
---|---|---|
1 | 6 | \(1 \leq n \leq 20\) |
2 | 17 | \(1 \leq n \leq 2000\) \(1 \leq k \leq 10000\) |
3 | 21 | \(1 \leq n \leq 2000\) |
4 | 27 | The tree is a line; every vertex has degree at most 2. |
5 | 29 | No additional constraints |
The first line contains one integer \(n\).
The second line contains one integer \(k\).
The third line contains \(n - 1\) integers, the \(i^{th}\) of which represents the first endpoint of the \(i^{th}\) edge (vertices 0-indexed).
The fourth line contains \(n - 1\) integers, the \(i^{th}\) of which represents the second endpoint of the \(i^{th}\) edge.
The fifth line contains one integer \(|I|\), the size of \(I\).
The sixth line contains \(I\) integers \(I_1, I_2, \ldots, I_{|I|}\), representing the elements of \(I\). It is guaranteed that \(I\) is a valid independent set.
Let your answer be the independent set \(S\) (If there is no valid \(S\), let \(S = \emptyset\)). Output one line containing \(|S|\) integers, the elements of \(S\) in ascending order.
Sample Input 1 | Sample Output 1 |
10
4
|
6 7 9
|
Subtask | Score |
---|---|
1 | 6 |
2 | 17 |
3 | 21 |
4 | 27 |
5 | 29 |
6 | 0 |