#arc143e. [arc143_e]Reversi

[arc143_e]Reversi

Problem Statement

We have a tree with NN vertices. The vertices are numbered 11 to NN, and the ii-th edge connects Vertex AiA_i and Vertex BiB_i. Additionally, each vertex has a reversi piece on it. The status of the piece on each vertex is given by a string SS: if the ii-th character of SS is B, the piece on Vertex ii is placed with the black side up; if the ii-th character of SS is W, the piece on Vertex ii is placed with the white side up.

Determine whether it is possible to perform the operation below NN times to remove the pieces from all vertices. If it is possible, find the lexicographically smallest possible sequence P1,P2,ldots,PNP_1, P_2, \\ldots, P_N such that Vertices P1,P2,ldots,PNP_1, P_2, \\ldots, P_N can be chosen in this order during the process.

  • 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.

Notes 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 SS and TT.

Below, let SiS_i denote the ii-th element of SS. Also, if SS is lexicographically smaller than TT, we will denote that fact as SltTS \\lt T; if SS is lexicographically larger than TT, we will denote that fact as SgtTS \\gt T.

  1. Let LL be the smaller of the lengths of SS and TT. For each i=1,2,dots,Li=1,2,\\dots,L, we check whether SiS_i and TiT_i are the same.
  2. If there is an ii such that SineqTiS_i \\neq T_i, let jj be the smallest such ii. Then, we compare SjS_j and TjT_j. If SjS_j is less than TjT_j (as a number), we determine that SltTS \\lt T and quit; if SjS_j is greater than TjT_j, we determine that SgtTS \\gt T and quit.
  3. If there is no ii such that SineqTiS_i \\neq T_i, we compare the lengths of SS and TT. If SS is shorter than TT, we determine that SltTS \\lt T and quit; if SS is longer than TT, we determine that SgtTS \\gt T and quit.

Constraints

  • 1leqNleq2times1051 \\leq N \\leq 2\\times 10^5
  • 1leqAi,BileqN1 \\leq A_i, B_i \\leq N
  • The given graph is a tree.
  • SS is a string of length NN consisting of the characters B and W.

Input

Input is given from Standard Input in the following format:

NN A1A_1 B1B_1 vdots\\vdots AN1A_{N-1} BN1B_{N-1} SS

Output

If the objective is unachievable, print -1. If it is achievable, print the answer in the following format:

P1P_1 P2P_2 cdots\\cdots PNP_N


Sample Input 1

4
1 2
2 3
3 4
WBWW

Sample Output 1

1 2 4 3 

Sample Input 2

4
1 2
2 3
3 4
BBBB

Sample Output 2

-1

In this case, you cannot perform the operation at all.