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.
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted