A13634 | Inverse Genealogy
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, except for one special person, who does not have any children. The people in this structure are conveniently numbered from $1$ to $n$ , and $s_i$ denotes the child of the person $i$ (and $s_i = 0$ for exactly one person who does not have any children).
We say that $a$ is an ancestor of $b$ if either $a = b$ , or $a$ has a child, who is an ancestor of $b$ . That is $a$ is an ancestor for $a$ , $s_a$ , $s_{s_a}$ , etc.
We say that person $i$ is imbalanced in case this person has both parents specified, and the total number of ancestors of one of the parents is at least double the other.
Ivan counted the number of imbalanced people in the structure, and got $k$ people in total. However, he is not sure whether he computed it correctly, and would like to check if there is at least one construction with $n$ people that have $k$ imbalanced people in total. Please help him to find one such construction, or determine if it does not exist.
We say that $a$ is an ancestor of $b$ if either $a = b$ , or $a$ has a child, who is an ancestor of $b$ . That is $a$ is an ancestor for $a$ , $s_a$ , $s_{s_a}$ , etc.
We say that person $i$ is imbalanced in case this person has both parents specified, and the total number of ancestors of one of the parents is at least double the other.
Ivan counted the number of imbalanced people in the structure, and got $k$ people in total. However, he is not sure whether he computed it correctly, and would like to check if there is at least one construction with $n$ people that have $k$ imbalanced people in total. Please help him to find one such construction, or determine if it does not exist.
输入格式
The input contains two integers $n$ and $k$ ( $1 \leq n \leq 100\,000$ , $0 \leq k \leq n$ ), the total number of people and the number of imbalanced people.
输出格式
If there are no constructions with $n$ people and $k$ imbalanced people, output NO.
Otherwise output YES on the first line, and then $n$ integers $s_1, s_2, \ldots, s_n$ ( $0 \leq s_i \leq n$ ), which describes the construction and specify the child of each node (or 0, if the person does not have any children).
Otherwise output YES on the first line, and then $n$ integers $s_1, s_2, \ldots, s_n$ ( $0 \leq s_i \leq n$ ), which describes the construction and specify the child of each node (or 0, if the person does not have any children).
输入输出样例
输入 #1
3 0
输出 #1
YES 0 1 1
输入 #2
5 1
输出 #2
YES 0 1 1 3 3
输入 #3
3 2
输出 #3
NO
In the first example case one can have a construction with 3 people, where 1 person has 2 parents.
In the second example case one can use the following construction:
Only person 1 is imbalanced, because one of their parents has 1 ancestor in total, and the other parent has 3 ancestors.
In the second example case one can use the following construction:
Only person 1 is imbalanced, because one of their parents has 1 ancestor in total, and the other parent has 3 ancestors.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted