A10557. Tree of Life (medium)
编程题
普及/提高-
知识点
题目描述
The first line of the input contains $Z<=20$ – the number of test cases. $Z$ descriptions of single test cases follow.
In each test case, the first line of input contains numbers $n$ ( $2<=n<=100$ ) and $k$ (where $k$ is the number of drawings; we have $k=n$ ). In the following lines, the descriptions of the $k$ drawings are given. The description of the $i$ -th drawing is a line containing $m_{i}$ – the number of edges in this drawing, followed by $m_{i}$ lines describing edges, each of which contains two space-separated integers –- the numbers of the two vertices connected by the edge.
In each test case, the first line of input contains numbers $n$ ( $2<=n<=100$ ) and $k$ (where $k$ is the number of drawings; we have $k=n$ ). In the following lines, the descriptions of the $k$ drawings are given. The description of the $i$ -th drawing is a line containing $m_{i}$ – the number of edges in this drawing, followed by $m_{i}$ lines describing edges, each of which contains two space-separated integers –- the numbers of the two vertices connected by the edge.
输入格式
If Heidi's drawings cannot possibly come from a single tree, you should output the word NO. Otherwise, output one line containing the word YES and $n-1$ lines describing any tree that Heidi's drawings could have come from. For every edge you should output the numbers of the vertices that it connects, separated with a single space. If there are many solutions, print any of them.
输出格式
无
输入输出样例
输入 #1
1 5 5 2 4 1 2 1 1 3 1 3 4 1 4 3 2 1 3 3 1 3 2 4 1 3 2 1 3 2 4 2
输出 #1
YES 2 5 4 2 3 2 5 1
输入 #2
5 1 2 2 3 3 4 3 5
输出 #2
4
说明/提示
In the second sample, there are four lifelines: paths between vertices $1$ and $3$ , $2$ and $4$ , $2$ and $5$ , and $4$ and $5$ .