A11862 | The Number Games
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The nation of Panel holds an annual show called The Number Games, where each district in the nation will be represented by one contestant.
The nation has $n$ districts numbered from $1$ to $n$ , each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$ .
This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
The nation has $n$ districts numbered from $1$ to $n$ , each district has exactly one path connecting it to every other district. The number of fans of a contestant from district $i$ is equal to $2^i$ .
This year, the president decided to reduce the costs. He wants to remove $k$ contestants from the games. However, the districts of the removed contestants will be furious and will not allow anyone to cross through their districts.
The president wants to ensure that all remaining contestants are from districts that can be reached from one another. He also wishes to maximize the total number of fans of the participating contestants.
Which contestants should the president remove?
输入格式
The first line of input contains two integers $n$ and $k$ ( $1 \leq k < n \leq 10^6$ ) — the number of districts in Panel, and the number of contestants the president wishes to remove, respectively.
The next $n-1$ lines each contains two integers $a$ and $b$ ( $1 \leq a, b \leq n$ , $a \ne b$ ), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts.
The next $n-1$ lines each contains two integers $a$ and $b$ ( $1 \leq a, b \leq n$ , $a \ne b$ ), that describe a road that connects two different districts $a$ and $b$ in the nation. It is guaranteed that there is exactly one path between every two districts.
输出格式
Print $k$ space-separated integers: the numbers of the districts of which the contestants should be removed, in increasing order of district number.
输入输出样例
输入 #1
6 3 2 1 2 6 4 2 5 6 2 3
输出 #1
1 3 4
输入 #2
8 4 2 6 2 7 7 8 1 2 3 1 2 4 7 5
输出 #2
1 3 4 5
In the first sample, the maximum possible total number of fans is $2^2 + 2^5 + 2^6 = 100$ . We can achieve it by removing the contestants of the districts 1, 3, and 4.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted