#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 (0≤ci≤10 \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 cv←1−cvc_v \gets 1 - c_v. After all operations, we obtain a tree T′T', where the color of node ii becomes ci′c'_i.

Now you are given the final tree T′T' and the color ci′c'_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 1≤u≤n1 \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,u≠c2,uc_{1,u} \neq c_{2,u}.

Input Format

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

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

The next n−1n - 1 lines each contain two positive integers u,vu, v (1≤u,v≤n1 \le u, v \le n, u≠vu \neq v), indicating that there is an edge (u,v)(u, v) in T′T'. 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