QOJ.ac

QOJ

حد الوقت: 7 s حد الذاكرة: 512 MB مجموع النقاط: 100

#2882. 新黑白树

الإحصائيات

Naomi 了解了红黑树,现在是时候学习白黑树了。她正在读一本算法书。书中有些页面包含树的图片,但这些树的边在岁月中已经褪色了。根据书中的文字,这些边中的每一条都应该是白色或黑色的。

Naomi 注意到每个顶点旁边都写着两个整数。她猜测第一个整数是与该顶点关联的白色边的数量,第二个整数是与该顶点关联的黑色边的数量。

Naomi 重建了所有的图片。你能做到吗?

输入格式

第一行包含一个整数 $t$ —— 需要重建的图片数量 ($1 \le t \le 3 \cdot 10^5$)。

接下来的行描述了 $t$ 幅图片。每幅图片的描述以一行包含一个整数 $n$ 开始 —— 树中的顶点数量 ($1 \le n \le 3 \cdot 10^5$)。

图片描述中接下来的 $n$ 行,第 $i$ 行包含两个整数 $w_i$ 和 $b_i$ —— 写在树的第 $i$ 个顶点旁边的两个整数:与第 $i$ 个顶点关联的白色边和黑色边的数量 ($0 \le w_i, b_i \le n - 1$)。

保证所有图片中 $n$ 的总和不超过 $3 \cdot 10^5$。

输出格式

输出 $t$ 个块,第 $i$ 个块应包含关于重建第 $i$ 幅图片的信息。

在每个块的第一行,如果无法重建,打印 “No”;如果至少有一种方法可以重建该图片,打印 “Yes”。如果存在重建树的方法,则额外打印 $n - 1$ 行,每行包含两个整数和一个字母 ‘W’(代表白色)或 ‘B’(代表黑色):$v_i, u_i$ 和 $c_i$,定义了顶点 $v_i$ 和 $u_i$ 之间颜色为 $c_i$ 的边 ($1 \le v_i, u_i \le n$;$c_i$ 为 ‘W’ 或 ‘B’)。

如果存在多种重建图片的方法,你可以打印其中任意一种。树的边可以以任何顺序打印。

样例

输入 1

6
4
1 1
1 1
1 0
1 0
4
1 0
2 1
1 1
1 0
1
0 0
2
0 1
0 1
2
1 0
0 1
3
2 0
0 1
0 1

输出 1

Yes
1 4 W
2 3 W
2 1 B
No
Yes
Yes
2 1 B
No
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.