{"problem":{"name":"Reversi","description":{"content":"We have a tree with $N$ vertices. The vertices are numbered $1$ to $N$, and the $i$\\-th edge connects Vertex $A_i$ and Vertex $B_i$. Additionally, each vertex has a reversi piece on it. The status of ","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc143_e"},"statements":[{"statement_type":"Markdown","content":"We have a tree with $N$ vertices. The vertices are numbered $1$ to $N$, and the $i$\\-th edge connects Vertex $A_i$ and Vertex $B_i$. Additionally, each vertex has a reversi piece on it. The status of the piece on each vertex is given by a string $S$: if the $i$\\-th character of $S$ is `B`, the piece on Vertex $i$ is placed with the black side up; if the $i$\\-th character of $S$ is `W`, the piece on Vertex $i$ is placed with the white side up.\nDetermine whether it is possible to perform the operation below $N$ times to remove the pieces from all vertices. If it is possible, find the lexicographically smallest possible sequence $P_1, P_2, \\ldots, P_N$ such that Vertices $P_1, P_2, \\ldots, P_N$ can be chosen in this order during the process.\n\n*   Choose a vertex containing a piece with the white side up, and remove the piece from that vertex. Then, flip all pieces on the vertices adjacent to that vertex.\n\nNotes on reversi pieces A reversi piece has a black side and a white side, and flipping it changes which side faces up. What is the lexicographical order on sequences?The following is an algorithm to determine the lexicographical order between different sequences $S$ and $T$.\nBelow, let $S_i$ denote the $i$\\-th element of $S$. Also, if $S$ is lexicographically smaller than $T$, we will denote that fact as $S \\lt T$; if $S$ is lexicographically larger than $T$, we will denote that fact as $S \\gt T$.\n\n1.  Let $L$ be the smaller of the lengths of $S$ and $T$. For each $i=1,2,\\dots,L$, we check whether $S_i$ and $T_i$ are the same.\n2.  If there is an $i$ such that $S_i \\neq T_i$, let $j$ be the smallest such $i$. Then, we compare $S_j$ and $T_j$. If $S_j$ is less than $T_j$ (as a number), we determine that $S \\lt T$ and quit; if $S_j$ is greater than $T_j$, we determine that $S \\gt T$ and quit.\n3.  If there is no $i$ such that $S_i \\neq T_i$, we compare the lengths of $S$ and $T$. If $S$ is shorter than $T$, we determine that $S \\lt T$ and quit; if $S$ is longer than $T$, we determine that $S \\gt T$ and quit.\n\n## Constraints\n\n*   $1 \\leq N \\leq 2\\times 10^5$\n*   $1 \\leq A_i, B_i \\leq N$\n*   The given graph is a tree.\n*   $S$ is a string of length $N$ consisting of the characters `B` and `W`.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$A_1$ $B_1$\n$\\vdots$\n$A_{N-1}$ $B_{N-1}$\n$S$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc143_e","tags":[],"sample_group":[["4\n1 2\n2 3\n3 4\nWBWW","1 2 4 3"],["4\n1 2\n2 3\n3 4\nBBBB","\\-1\n\nIn this case, you cannot perform the operation at all."]],"created_at":"2026-03-03 11:01:14"}}