Codeforces Round 1060 (Div. 2)
D
Catshock
Codeforces
1900
原题
← C2E →
翻译中…

A cat lives on a tree with $n$ nodes. The cat starts on node $1$, and you live on node $n$. You are going to leave the cat a note written in the parkour language to help it reach you.

翻译中…

The parkour language has two types of instructions:

翻译中…
  • $1$ — This means that the cat should move to any adjacent node to it, if there are multiple options, it will pick one of them arbitrarily. If there are no adjacent nodes to it, then it will not move.
  • $2\,u$ — This means to destroy node $u$ and all adjacent edges to it. If the cat is currently on node $u$, it will die, so this should be avoided. If node $u$ was already destroyed, then nothing will happen.
翻译中…

Additionally, there cannot be two consecutive instances of the second instruction.

翻译中…

Unfortunately, the parkour language is ambiguous because the cat may have multiple options for each instance of the first instruction. So you should construct a sequence of instructions of length at most $3n$ so that if the cat follows them, it will end at node $n$, no matter what choices it makes. It can be proven that such a sequence exists for any tree.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each testcase contains an integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the size of the tree.

翻译中…

Then $n - 1$ lines follow, each of them contains two integers $u$ and $v$ ($1 \le u,v \le n, u \ne v$) which describe a pair of vertices connected by an edge. It is guaranteed that the given graph is a tree and has no loops or multiple edges.

翻译中…

The sum of $n$ across all testcases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each testcase, output a single integer $k$ ($0 \le k \le 3n$) — the number of operations you will perform.

翻译中…

Then output $k$ lines of either of the following formats:

翻译中…
  • $1$ — make the cat move to an adjacent node if there are nodes adjacent to it.
  • $2\,u$ ($1 \le u \le n$) — delete node $u$ along with all adjacent edges
翻译中…

Note

翻译中…

There are extra spaces between the output of different test cases only for clarity, and the participants are not expected to print them.

翻译中…

The path of the cat in the first testcase is shown below.

翻译中…

image

翻译中…

It can be shown that this is the only possible path, and so the cat will always end at node $5$.

翻译中…

An example of a sequence of instructions that does not work for the first testcase is: $\mathtt{1}$, $\mathtt{2}$ $\mathtt{2}$. As the following may happen:

翻译中…

image

翻译中…

Here the cat died at node $2$.

翻译中…

样例

Input #1
4
5
1 2
2 3
1 5
5 4
2
1 2
4
1 2
1 3
1 4
6
1 2
1 3
3 4
4 5
4 6
Output #1
2
2 2
1

1
1

5
2 2
1
1
2 3
1

9
2 2
1
2 1
1
2 3
1
1
2 5
1
InputCopy OutputCopy
题目信息
题号
2154D
时间限制
2 s
内存限制
256 MB
标签
构造
DFS 及类似
图论
树
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。