thesis
Test Question
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:
- Given a tree of vertices and an independent set , find the independent set whose lexicographical order is exactly larger than .
WrongAnswer asks you to test this problem for him. Here are some definitions that may be useful:
- An independent set is a subset of satisfying the condition that any two vertices in are not adjacent in the tree. In other words, there are no two vertices with .
- Suppose you have two vertex sets . Let the vertex indices in be in ascending order; and similarly, let the indices in be in ascending order. Then, is lexicographically smaller than if on the lowest where and differ, .
If all independent sets of were sorted lexicographically under these definitions, would be the set in the order. Output the set in the order, or the empty set if no such set exists.
Limits
Subtasks #
|
Score
|
Constraints
|
1 |
6 |
|
2 |
17 |
|
3 |
21 |
|
4 |
27 |
The tree is a line; every vertex has degree at most 2. |
5 |
29 |
No additional constraints |
Input format
The first line contains one integer .
The second line contains one integer .
The third line contains integers, the of which represents the first endpoint of the edge (vertices 0-indexed).
The fourth line contains integers, the of which represents the second endpoint of the edge.
The fifth line contains one integer , the size of .
The sixth line contains integers , representing the elements of . It is guaranteed that is a valid independent set.
Output format
Let your answer be the independent set (If there is no valid , let ). Output one line containing integers, the elements of in ascending order.
Samples
Sample Input 1
|
Sample Output 1
|
10
4
0 1 1 1 1 4 0 7 0
1 2 3 4 5 6 7 8 9
3
5 8 9
|
6 7 9
|