QOJ.ac

QOJ

Limite de temps : 5.0 s Limite de mémoire : 1024 MB Points totaux : 100

#10688. AmazingTalker

Statistiques

Frank 是 AmazingTalker 的一名新老师,他观察到那里的老师们拥有不同的才华。在 AmazingTalker 上,如果一位老师在至少一个方面拥有更强的能力,那么另一位老师就会称其为“老师”。就像国立台湾大学的学生一样。

每位老师都有两种不同的能力:围棋和钢琴,分别由两个排名 $x_i$ 和 $y_i$ 表示。请注意,排名越低代表该技能的能力越强。例如,围棋排名为 1 的老师在围棋方面比围棋排名为 2 的老师更强。

Frank 想知道是否可以在所有老师之间构建一个友谊图,使得每位老师的朋友中,有一半以上的人是他们的“老师”。形式化地说,每位老师认为他们朋友中超过一半的人在围棋、钢琴或两者方面都比自己拥有严格更强的能力。

你的任务是确定是否可以构建这样的关系图,如果可以,请输出老师之间的关系。

输入格式

第一行包含一个整数 $N$,表示老师的数量 ($1 \le N \le 5 \cdot 10^5$)。接下来的 $N$ 行,每行包含两个整数 $x_i$ 和 $y_i$,分别表示第 $i$ 位老师的围棋能力排名和钢琴能力排名 ($1 \le x_i, y_i \le N$)。注意,不同的老师可能拥有相同的排名,因为他们可能在同一项技能上水平相当。

输出格式

如果无法创建这样的关系图,请在单行上输出 “No”。如果可以创建该图,请在单行上输出 “Yes”。此外,你需要输出老师之间的关系。

关系格式如下:第一行包含一个整数 $M$,表示师生关系的对数 ($0 \le M \le 3.1416 \cdot N$)。接下来的 $M$ 行,每行包含两个整数 $u_i$ 和 $v_i$,表示第 $u_i$ 位老师和第 $v_i$ 位老师是朋友 ($u_i \neq v_i$)。每种友谊关系不能被列出超过一次。

此外,可以证明如果答案为 “Yes”,我们总能找到一个满足 $M \le 3.1416 \cdot N$ 的图。因此,你输出的关系数量不应超过 $3.1416 \cdot N$。

样例

样例输入 1

2
1 2
2 1

样例输出 1

Yes
1
1 2

样例输入 2

2
1 1
2 2

样例输出 2

No

样例输入 3

5
1 2
3 3
1 5
4 1
5 4

样例输出 3

Yes
3
1 4
2 4
3 5

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#535Editorial Open集训队作业 解题报告 by 李秉霈Qingyu2026-01-02 21:53:39 Download
#525Editorial Open集训队作业 解题报告 by 刘墨涵Qingyu2026-01-02 21:43:09 Download

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.