#P13310. 染紫

    ID: 11598 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创O2优化树形 DP组合数学洛谷月赛

染紫

Description

Yuki has a tree of size nn.

Yuki defines the weight of a tree coloring scheme as follows:

Let aa be the sum of the squares of the sizes of all red maximal connected components.

Let bb be the sum of the squares of the sizes of all blue maximal connected components.

The weight of this coloring scheme is abab.

Some nodes on the tree have already been colored red or blue. Color the remaining nodes red or blue, and find the sum of the weights of all valid coloring schemes.

Let the number of nodes to be colored be CC. Then there are 2C2^C valid coloring schemes in total.

The answer may be very large, so please modulo 998244353998244353.

Input Format

The first line inputs an integer nn.

The next n1n-1 lines each contain two integers uiu_i and viv_i, representing an edge (ui,vi)(u_i, v_i) on the tree.

The next line contains a string ss of nn characters.

When si=rs_i=\texttt{r}, the node is red.

When si=bs_i=\texttt{b}, the node is blue.

When si=ws_i=\texttt{w}, the node is to be colored.

Output Format

Output the answer modulo 998244353998244353.

6
1 2
1 3
1 4
2 5
2 6
rbwrbw
186
20
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
wwwwwwwwwwwwwwwwwwww
678428480
10
1 2
2 3
3 4
3 5
3 6
3 7
5 8
7 9
4 10
wbwwwrwrrw
8056
4
1 2
1 3
2 4
rbbr
4
5
1 2
1 3
2 4
3 5
wbwrw
100
7
1 2
1 3
2 4
2 5
3 6
3 7
wbwrwbr
294

Hint

Sample 1 explanation:

Test Case Distribution

ID Points Range of nn Special Properties
0 10 n10n \le 10
1 n40n \le 40 si=ws_i =\texttt{w}
2 n300n \le 300
3 n5000n \le 5000
4 n106n \le 10^6 si{r,b}s_i \in \{\texttt{r},\texttt{b}\}
5 n2×105n \le 2\times 10^5 si{r,w}s_i \in \{\texttt{r},\texttt{w}\}
6 si=ws_i =\texttt{w}
7 n2×106n \le 2\times 10^6 ui=vi1u_i=v_i-1
8 n106n \le 10^6 ui=1u_i=1
9 n2×106n \le 2\times 10^6

For all data: 1n2×1061\le n \le 2\times 10^6, si{r,w,b}s_i \in \{\texttt{r},\texttt{w},\texttt{b}\}, 1ui,vin1\le u_i,v_i\le n.