405013: GYM101741 C Cover the Paths
Description
You are given an undirected unweighted tree consisting of n vertices labeled by integers 1, 2, ..., n. A total of m simple paths are chosen in this tree. Each path is described as a pair of its endpoints (ai, bi).
Let V be the set of all vertices of the tree. We say that subset S of V is good if for every i such that 1 ≤ i ≤ m, the simple path from ai to bi contains at least one vertex from S. We say that subset T be the best subset if T is a good subset and there is no good subset X such that |X| < |T|.
You have to find the best subset of V.
InputThe first line contains an integer n, the number of vertices in the tree (1 ≤ n ≤ 105).
Each of the next n - 1 lines describes an edge of the tree. Edge i is denoted by two integers ui and vi, the labels of vertices it connects (1 ≤ ui, vi ≤ n, ui ≠ vi). It is guaranteed that the given edges form a tree.
The next line contains an integer m, the number of paths (1 ≤ m ≤ 105).
Each of the next m lines describes a path in the tree. Path i is denoted by two integers ai and bi, the labels of the endpoints (1 ≤ ai, bi ≤ n). For some paths, it may be that ai = bi. It is not guaranteed that all paths are pairwise distinct.
OutputOn the first line, print the size of the best subset of V. On the second line, print the labels of vertices belonging to the best subset of V in any order.
If there are several possible solutions, print any one of them.
ExamplesInput4Output
1 2
2 3
2 4
2
1 2
4 2
1Input
2
6Output
1 2
2 3
3 4
5 6
5 2
5
2 1
6 6
1 4
3 4
4 1
3
6 3 1