#P12803. [AMPPZ 2019] Little Worm

[AMPPZ 2019] Little Worm

Description

Little Worm is living on a tree. The tree has n n vertices (and is a connected, undirected acyclic graph), and Worm occupies the whole path between the vertices a a and b b .

Worm would like to move to another path – the one between vertices c c and d d – as it is more sunny there. It is known that the paths ab a \leftrightarrow b and cd c \leftrightarrow d have no vertices in common.

To change its position on the tree, Worm can make some moves, which consist of entering a free vertex with Worm’s either end. Formally, if Worm is currently occupying a path between x x and y y , it may choose a new vertex z z adjacent to x x , which is not on the path xy x \leftrightarrow y . Then Worm frees (stops occupying) y y , taking z z instead. In a similar way, Worm can choose a vertex z z' adjacent to y y , free x x and occupy z z' . After a single move Worm still occupies some path, and its length does not change.

Worm is aiming to get to the path between c c and d d , but being quite lazy, it doesn’t plan for more than 10n 10 \cdot n moves. Can you help it reach its goal within that limit?

Input Format

The first line of input contains the number of test cases z z (1z7000 1 \leq z \leq 7000 ). The test cases follow, each one in the following format:

  • The first line of a test case contains a single integer n n (4n100000 4 \leq n \leq 100\,000 ) – the number of the vertices of a tree. Each of the following n1 n - 1 lines contains two integers u,v u, v (1uvn 1 \leq u \ne v \leq n ), describing the endpoints of a single edge.
  • In the next line two integers a a and b b (1abn 1 \leq a \ne b \leq n ) are given. These are the endpoints of the path that is Worm’s starting position.
  • The next line contains the endpoints of the path which is Worm’s goal, given as two integers c c and d d (1cdn 1 \leq c \ne d \leq n ).

The number of vertices on the path between a a and b b match the number of vertices on the path between c c and d d . You may also assume that those two paths have no common vertices.

The sum of all values of n n over all test cases does not exceed 1000000 1\,000\,000 .

Output Format

For every test case, if Worm cannot reach its goal in 10n 10 \cdot n moves, output 1-1. Otherwise, output a possible sequence of Worm’s moves in two lines:

  • First line: the number of moves q q (1q10n 1 \leq q \leq 10 \cdot n ),
  • Second line: q q integers v1,v2,,vq v_1, v_2, \ldots, v_q – the required moves.

For i=1,2,,q i = 1, 2, \ldots, q , the value vi v_i should denote the vertex which is entered by Worm in the i i -th move.

You may output any correct sequence that moves Worm to the goal and has no more than 10n 10 \cdot n moves (in particular, you do not have to minimize the number of moves). Assume that Worm is symmetrical – it can move in both directions and it can enter the goal path facing either side.

3
6
1 2
1 3
1 4
4 5
4 6
2 3
5 6
15
1 2
1 6
2 3
2 4
2 5
6 7
6 8
5 9
6 10
9 11
9 12
9 13
12 14
14 15
14 13
3 6
6
1 2
1 3
2 4
4 5
5 6
4 6
3 2
-1
7
15 5 2 1 6 7 3
3
2 1 3