Degree of Spanning Tree
Time limit3sMemory limit512 MB
Given a connected graph, find a spanning tree in which every vertex has degree at most n/2, or report that no such tree exists.
Problem
You are given an undirected connected graph with vertices and edges. Find a spanning tree of the graph such that every vertex in the tree has degree at most .
The degree of a vertex is the number of edges connected to it.
Input
The first line contains an integer , the number of test cases. For each test case:
The first line contains two integers and (, ), the number of vertices and edges.
The next lines each contain two integers and (), meaning there is an edge between vertices and . The graph may contain self loops and multiple edges.
The graph is guaranteed to be connected. The sum of over all test cases does not exceed , and the sum of does not exceed .
Output
For each test case, if a valid spanning tree exists, print "Yes" on one line. Then print lines, each with two integers and , meaning the tree contains an edge between and .
If no valid spanning tree exists, print "No" on one line.
Hint
In the first sample, the maximum degree in the spanning tree is 3 (vertices 1 and 4 both have degree 3). Since , the answer is valid.
In the second sample, every spanning tree has a vertex with degree 2. Since , no valid answer exists.