QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 1024 MB 總分: 100

#5209. 国王的拼图

统计

King Kendrick 是 Kotlin 王国的统治者。他正在为下一届政府会议做准备。Kotlin 王国由 $n$ 个城市组成。这些城市需要通过若干双向道路连接起来。由于各个部门负责王国居民安全和舒适的各个方面,其中一些部门提出了以下要求:

  • “所有城市都应通过新道路连接起来” —— 交通与数字基础设施部。
  • “不得有环路 —— 即连接城市自身的道路” —— 环境部。
  • “一对城市之间最多只能有一条道路” —— 财政部。
  • “如果 $a_i$ 是连接到第 $i$ 个城市的道路数量,那么集合 $\{a_1, \dots, a_n\}$ 应该恰好包含 $k$ 个不同的数字” —— ICPC 部。

King Kendrick 对 ICPC 部的要求感到困扰。他请求你帮助他。请找到满足上述所有要求的任意一组道路,或者说明这是不可能的。

输入格式

输入仅一行,包含两个整数 $n$ 和 $k$ ($1 \le k \le n \le 500$)。

输出格式

如果无法满足所有要求,仅输出 “NO”。 否则,第一行输出 “YES”。 第二行输出 $m$ —— 道路的数量 ($0 \le m \le \frac{n(n-1)}{2}$)。 接下来的 $m$ 行应包含一对整数 $a$ 和 $b$ —— 通过道路连接的城市 ($1 \le a, b \le n$)。

样例

样例输入 1

5 2

样例输出 1

YES
4
1 2
1 3
1 4
1 5

说明 1

城市 1 连接了四条道路,而其他城市恰好连接了一条。

样例输入 2

4 1

样例输出 2

YES
4
1 2
2 3
3 4
4 1

说明 2

每个城市恰好连接了两条道路。

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.