QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15238. Infection

Statistiques

oql has planted a Longan tree. This Longan tree is an undirected connected graph consisting of $n$ nodes and $n-1$ edges. Every node on the Longan tree has a bunch of sweet and juicy Longans. It is the season to harvest the Longans, and one morning, oql went to check on the status of his Longan tree. He discovered some very unfortunate news: his Longan tree has been attacked by pests! If some Longans on the tree are infested, they will spread.

Specifically, the pests spread by laying eggs on the nodes of the Longan tree. A node becomes infested if and only if it has at least one egg on it. On day $0$, the pests choose one node on the tree to lay an egg. Every day, all nodes that are currently infested will lay an egg on all their adjacent nodes (regardless of whether the adjacent nodes are already infested; two nodes are adjacent if there is an edge directly connecting them). Please note that if an infested node has multiple eggs, it will still only lay one egg on each adjacent node per day.

Clearly, the node chosen by the pests on day $0$ will affect the subsequent order of infestation and the total number of eggs. oql wants to know which nodes, when chosen as the initial node for the pests, satisfy the condition that the total number of eggs on the Longan tree after $L = 2025^{5^{18}}$ days is maximized.

Specifically, let $f(i)$ ($1 \le i \le n$) denote the total number of eggs on the Longan tree after $L$ days if the pests start at node $i$. oql wants to find all nodes $i$ such that $f(i) = \max_{1 \le j \le n} f(j)$.

Input

The first line contains an integer $T$ ($1 \le T \le 10^4$), representing the number of test cases.

For each test case, the first line contains an integer $n$ ($1 \le n \le 5 \times 10^5$).

The next $n-1$ lines each contain two integers $u, v$ ($1 \le u, v \le n$), representing an edge of the tree.

The sum of $n$ over all $T$ test cases is at most $5 \times 10^5$.

Output

For each test case, output two lines. The first line contains an integer $s$ ($1 \le s \le n$), representing the number of nodes that satisfy the condition. The second line contains $s$ integers, outputting the indices of all nodes that satisfy the condition in ascending order.

Examples

Input 1

2
2
1 2
4
1 2
2 4
1 3

Output 1

2
1 2
2
1 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.