CF690F2.Tree of Life (medium)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The first line of the input contains Z<=20Z<=20 – the number of test cases. ZZ descriptions of single test cases follow.

In each test case, the first line of input contains numbers nn ( 2<=n<=1002<=n<=100 ) and kk (where kk is the number of drawings; we have k=nk=n ). In the following lines, the descriptions of the kk drawings are given. The description of the ii -th drawing is a line containing mim_{i} – the number of edges in this drawing, followed by mim_{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 n1n-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 11 and 33 , 22 and 44 , 22 and 55 , and 44 and 55 .

首页