QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100

#18449. 树

统计

Vasya 深入研究了图论。他阅读了关于树的章节,有一个问题一直困扰着他:他必须构建一棵拥有 $N$ 个节点的有根树,其中除了叶子节点外,每个节点都恰好有 $K$ 个子节点。答案必须以边集列表的形式写成一个字符串;在所有可能的方案中,他必须找到字典序最小的那一个。

边集列表按以下方式写入字符串。每条边由一对整数描述——即该边连接的两个节点的编号。这两个数字在书写时不能有前导零,且它们之间必须恰好有一个空格。该字符串由图中所有 $N - 1$ 条边的描述拼接而成,相邻两条边的描述之间用一个空格隔开。假设所有节点从 $1$ 到 $N$ 编号,其中根节点为 $1$ 号节点。

Vasya 必须找到一个字典序最小的字符串,该字符串可以通过上述方式由一棵满足要求的有根树生成。在进行字典序比较时,假设空格字符的字典序小于所有数字字符。

例如,我们构建一棵有 $5$ 个节点且所有非叶子节点都有 $2$ 个子节点的树。一棵包含边 $(1, 4), (1, 5), (4, 3), (4, 2)$ 的树符合要求。其边集列表可以用不同的方式写成字符串:

  • 4 2 4 3 1 4 1 5
  • 2 4 3 4 1 4 1 5
  • 1 4 1 5 2 4 3 4

在这里,后一个方案的字典序都比前一个方案小,但它们都不是最优的。对于当前的 $N$ 和 $K$ 值,字典序最小的字符串 1 2 1 3 2 4 2 5 是由另一棵不同的树生成的。

帮助 Vasya 解决这个问题,他马上就要迎来一场图论测试了!

输入格式

输入的第一行包含两个整数 $N$ 和 $K$,其中 $N$ 是所需树的节点数,$K$ 是非叶子节点的子节点数($2 \le N \le 10^5$,$1 \le K \le 10^5$)。

输出格式

如果不存在满足指定参数的树,则在输出的唯一一行中打印单词 No

否则,在输出的第一行打印单词 Yes;在第二行打印所需的字典序最小的字符串。

样例

输入样例 1

5 2

输出样例 1

Yes
1 2 1 3 2 4 2 5

输入样例 2

4 10

输出样例 2

No

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.