题库练习 Tree of Life (medium)
← 上一题 下一题 →

A10557 | Tree of Life (medium)

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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.

输入格式

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
C++ 编辑器
输入
输出