Minimum Sequence Spanning Tree
题号:NC217567
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

    Given a tree with  vertices numbered from 1 to , we say a sequence  is a "spanning sequence" of the tree if it passes the following validation:

  • Paint all the vertices white at the beginning;
  • Select vertex  as the root and paint it black. Now the tree becomes a rooted tree and each vertex except  has a parent;
  • Enumerate  from 2 to . If the parent of vertex  is black, also paint vertex  black, otherwise do nothing;
  • If all the vertices turn black, sequence  is a spanning sequence of the tree.
    It's obvious that the spanning sequence of a given tree is not unique. For example, for the tree shown below, both {2, 1, 5, 3, 4} and {1, 2, 3, 4, 5} are its spanning sequences.
    

    We now present you with a connected graph with  vertices and  edges. Please find a spanning tree of this graph such that the minimum spanning sequence of the tree is as large as possible. In this problem, we compare the sequences by lexicographic order.

    In case you're not familiar with some concepts referred above:

  • A tree is a connected graph with  vertices and  edges.
  • A spanning tree of a graph is a sub-graph of the original graph such that it contains all the vertices of the original graph and is a tree.
  • Sequence  is lexicographically smaller than sequence  if there exists an integer  such that  for all  and .

输入描述:

    There are multiple test cases. The first line of the input contains an integer  indicating the number of test cases. For each test case:

    The first line of the input contains two integers  and  (), indicating the number of vertices and edges of the graph.

    For the following  lines, the -th line contains two integers  and  (), indicating that there is an edge connecting vertex  and .

    It's guaranteed that:

    - There are no self loops or multiple edges.
    - The given graph is connected.
    - Neither the sum of  nor the sum of  will exceed .

输出描述:

    For each test case output one line containing  integers separated by a space, indicating the minimum spanning sequence of the desired spanning tree.
示例1

输入

复制
2
4 5
1 2
1 4
2 3
2 4
3 4
4 3
3 2
4 1
1 3

输出

复制
1 4 3 2
1 3 2 4