CF1379E.Inverse Genealogy

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

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 11 to nn, and sis_i denotes the child of the person ii (and si=0s_i = 0 for exactly one person who does not have any children).

We say that aa is an ancestor of bb if either a=ba = b, or aa has a child, who is an ancestor of bb. That is aa is an ancestor for aa, sas_a, ssas_{s_a}, etc.

We say that person ii 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 kk 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 nn people that have kk imbalanced people in total. Please help him to find one such construction, or determine if it does not exist.

伊万对家谱学很感兴趣。目前,他正在研究一种特殊的家谱结构,该结构由若干人组成。在此结构中,每个人要么父母双方均被指定,要么父母双方均未被指定。此外,除一位特殊人物外,其余每个人都恰好有一个孩子;这位特殊人物没有孩子。该结构中的人物被方便地编号为 11 到 nn,且 sis_i 表示人物 ii 的孩子(恰好有一个人满足 si=0s_i = 0,即此人没有孩子)。

我们称 aa 是 bb 的祖先,当且仅当 a=ba = b,或 aa 有一个孩子,而该孩子是 bb 的祖先。换言之,aa 是其自身、sas_a、ssas_{s_a} 等所有后代的祖先。

若某个人 ii 的父母双方均被指定,且其中一位父母的祖先总数至少是另一位父母祖先总数的两倍,则称该人 ii 是不平衡的。

伊万统计了该结构中不平衡人物的数量,得到总数为 kk。然而,他不确定自己的计算是否正确,因此希望验证:是否存在一个包含 nn 个人的结构,使得其中恰好有 kk 个不平衡人物?请帮助他构造出这样一个结构,或判定其不存在。

输入格式

The input contains two integers nn and kk (1≤n≤100 0001 \leq n \leq 100\,000, 0≤k≤n0 \leq k \leq n), the total number of people and the number of imbalanced people.

输入包含两个整数 nn 和 kk(1≤n≤100 0001 \leq n \leq 100\,000,0≤k≤n0 \leq k \leq n),分别表示总人数和不平衡人数。

输出格式

If there are no constructions with nn people and kk imbalanced people, output NO.

Otherwise output YES on the first line, and then nn integers s1,s2,…,sns_1, s_2, \ldots, s_n (0≤si≤n0 \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).

如果不存在由 nn 个人和 kk 个不平衡人员构成的构造,则输出 NO。

否则,第一行输出 YES,然后输出 nn 个整数 s1,s2,…,sns_1, s_2, \ldots, s_n(其中 0≤si≤n0 \leq s_i \leq n),描述该构造,其中 sis_i 表示第 ii 个人的孩子(若该人没有孩子,则 si=0s_i = 0)。

输入输出样例

  • 输入#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.

在第一个样例中,可以构造一个包含 3 人的家谱,其中 1 人有 2 位父母。

在第二个样例中,可采用如下构造:

仅有第 1 号人物是不平衡的,因为其一位父母总共有 1 位祖先,而另一位父母则有 3 位祖先。

输入解题思路,AI测评打分。不知道怎么写?

首页