ユニークビジョンプログラミングコンテスト2025 クリスマス(AtCoder Beginner Contest 437)
G
Colorful Christmas Tree
AtCoder
⌀ 2806
原题
翻译中…

Problem Statement

翻译中…

The Christmas season this year is over, and it is finally time for the new year. Takahashi is busy with the big cleanup of putting away the Christmas tree.

翻译中…

There is a Christmas tree decorated with bulbs in three colors: red, blue, and green. The Christmas tree has $N$ bulbs, and they are connected by $N-1$ ribbons. When viewing the bulbs as vertices and the ribbons as edges, this graph is a tree.

翻译中…

The bulbs are numbered from $1$ to $N$, and the ribbons are numbered from $1$ to $N-1$. Ribbon $i$ connects bulbs $u_i$ and $v_i$. Bulb $i$ is initially lit in red if $c_i$ is R, in green if it is G, and in blue if it is B.

翻译中…

Takahashi is considering performing the following operation $N-1$ times to remove all ribbons.

翻译中…
  1. Choose one ribbon among those not yet removed where the bulbs at both ends have different colors, and remove that ribbon.
  2. Let bulbs $u$ and $v$ be the bulbs at both ends of the removed ribbon. For each of the bulbs $u$ and $v$, change the color they are lit in according to the following rule:
  • If it was lit in red, light it in green.
    • If it was lit in green, light it in blue.
    • If it was lit in blue, light it in red.
翻译中…

Determine whether it is possible for Takahashi to remove all ribbons by repeating this operation. If possible, output one such method.

翻译中…

You are given $T$ test cases. Solve each of them.

翻译中…

Constraints

翻译中…
  • $1\leq T\leq 20000$
  • $2\leq N\leq 2000$
  • $c_i$ is R, G, or B.
  • $1\leq u_i,v_i\leq N$
  • When viewing the bulbs as vertices and the ribbons as edges, the given graph is a tree.
  • $T,N,u_i,v_i$ are integers.
  • The sum of $N^2$ in one input file is at most $2000^2$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N
c_1c_2\ldots c_N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}

翻译中…

Output

翻译中…

Output the answers for $\mathrm{case}_1, \mathrm{case}_2, \ldots, \mathrm{case}_T$ in order in the following format.

翻译中…

If it is impossible to remove all ribbons, output No.

翻译中…

If it is possible, let $e_i$ be the number of the ribbon removed in the $i$-th operation, and output:

翻译中…

Yes
e_1 e_2 \ldots e_{N-1}

翻译中…

$(e_1, e_2, \ldots, e_{N-1})$ must be a permutation of $(1, 2, \ldots, N-1)$.

翻译中…

If there are multiple solutions, any of them will be accepted as correct.

翻译中…

样例

Input #1
3
4
GBBR
1 2
1 3
1 4
3
RRR
1 2
2 3
5
RGBRG
1 2
2 3
3 4
3 5
Output #1
Yes
1 3 2
No
Yes
1 4 2 3
For the first test case, for example, all ribbons can be removed by performing the operations as follows: - Initially, the colors of the bulbs are green, blue, blue, red, in order (from bulb $1$). - Remove ribbon $1$. After removal, the colors of the bulbs are blue, red, blue, red, in order. - Remove ribbon $3$. After removal, the colors of the bulbs are red, red, blue, green, in order. - Remove ribbon $2$. After removal, the colors of the bulbs are green, red, red, green, in order. The $(e_1, e_2, e_3)$ satisfying the condition are $(1, 3, 2)$ and $(2, 3, 1)$, and either one will be accepted as correct. For the second test case, it is impossible to remove all ribbons no matter how you perform the operations.

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。