CF690F2.Tree of Life (medium)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 mi – the number of edges in this drawing, followed by mi 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 .