A13207 | Modernization of Treeland
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases in the input. This is followed by the test cases themselves.
Each test case begins with a line that contains two integers $n$ and $k$ ( $2 \le n \le 3 \cdot 10^5$ , $1 \le k \le n$ ) — the number of cities in Treeland and the number of "dead-end" cities required in the subset $S$ .
This is followed by $n-1$ lines with road descriptions. Each road is given by two integers $x$ and $y$ ( $1 \le x, y \le n$ ; $x \ne y$ ) — the numbers of the cities that are connected by this road. It is guaranteed that from every city you can reach any other, moving only by the roads.
The sum of the values of $n$ for all test cases in the input does not exceed $3 \cdot 10^5$ .
Each test case begins with a line that contains two integers $n$ and $k$ ( $2 \le n \le 3 \cdot 10^5$ , $1 \le k \le n$ ) — the number of cities in Treeland and the number of "dead-end" cities required in the subset $S$ .
This is followed by $n-1$ lines with road descriptions. Each road is given by two integers $x$ and $y$ ( $1 \le x, y \le n$ ; $x \ne y$ ) — the numbers of the cities that are connected by this road. It is guaranteed that from every city you can reach any other, moving only by the roads.
The sum of the values of $n$ for all test cases in the input does not exceed $3 \cdot 10^5$ .
输入格式
For each test case print Yes or No (in any case, upper or lower), depending on whether the answer exists or not. If the answer exists, then print an integer $m$ ( $1 \le m \le n$ ) — the number of cities in the found subset. Then print $m$ different numbers from $1$ to $n$ — the numbers of the cities in the found subset. City numbers can be printed in any order. If there are several answers, print any of them.
输出格式
无
输入输出样例
输入 #1
4 10 4 4 5 5 2 2 1 1 3 1 9 9 10 2 7 7 8 5 6 4 3 1 2 2 3 3 4 5 3 1 2 1 3 1 4 1 5 4 1 1 2 2 4 2 3
输出 #1
Yes 9 1 2 4 5 6 7 8 9 10 No Yes 4 1 3 4 5 Yes 1 4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted