#P16961. [SCCPC 2026] 永恒的奥古斯都

    ID: 19045 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP四川树形 DP2026省赛/邀请赛

[SCCPC 2026] 永恒的奥古斯都

Problem Description

There is a tree TT with nn nodes, rooted at node 11. Initially, node ii has color cic_i (0ci10 \le c_i \le 1).

Little L performed several (possibly 00) operations. In each operation, she chooses a node uu such that cu=0c_u = 0, and for every node vv in the subtree of uu, she performs cv1cvc_v \gets 1 - c_v. After all operations, we obtain a tree TT', where the color of node ii becomes cic'_i.

Now you are given the final tree TT' and the color cic'_i of each node. You need to compute how many different possible initial states TT there could be. Output the answer modulo 998244353998244353.

In this problem, we consider two trees T1,T2T_1, T_2 to be different if and only if there exists a node 1un1 \le u \le n such that its color in T1T_1 is c1,uc_{1,u}, its color in T2T_2 is c2,uc_{2,u}, and c1,uc2,uc_{1,u} \neq c_{2,u}.

Input Format

The first line contains a positive integer nn (1n2×1051 \le n \le 2 \times 10^5), indicating the number of nodes in TT'.

The second line contains nn integers c1,c2,,cnc'_1, c'_2, \cdots, c'_n (0ci10 \le c'_i \le 1), representing the color of each node in the final state.

The next n1n - 1 lines each contain two positive integers u,vu, v (1u,vn1 \le u, v \le n, uvu \neq v), indicating that there is an edge (u,v)(u, v) in TT'. It is guaranteed that all edges form a tree.

Output Format

Output one integer in a single line, representing the number of possible initial states TT modulo 998244353998244353.

3
0 0 1
1 2
1 3
2
5
1 0 0 1 1
1 2
1 3
2 4
2 5
20

Hint

Translated by ChatGPT 5