Amazing Tree
시간 제한1초메모리 제한1024 MB
트리에서 시작 정점과 각 정점의 이웃 순서를 정해 DFS 후위 순회 목록이 사전순으로 가장 작게 만든다.
문제
Consider an undirected tree. The following algorithm constructs a post-order traversal of the tree:
fun dfs(v):
mark v as used
for u in neighbours(v):
if u is not used:
dfs(u)
append v to order
The post-order traversal will be in the list order.
You are allowed to choose the order of neighbors for each vertex as well as the starting vertex. What is the lexicographically minimal order you can get?
입력
The first line of input contains one integer () --- the number of test cases you need to process. Description of the test cases follows.
The first line of each test case contains a single integer () --- the number of vertices in the tree.
The -th of the next lines contains two integers (, ), meaning that there is an undirected edge in the tree. It is guaranteed that the given graph is a tree.
The sum of over all test cases in one test file does not exceed .
출력
For each test case print the lexicographically minimal order on a separate line.
힌트
The first test looks as follows:

By starting in vertex we can only get order . By starting in vertex we can only get order . By starting in vertex we can get two orders: and . The lexicographically minimal of the four orders is .
The second test looks as follows:

By starting in vertex we can get two orders: and . By starting in vertex we can only get order . By starting in vertex we can only get order . The lexicographically minimal of the four orders is .
The third test looks as follows:

The lexicographically minimal order is it can be obtained by starting in node .