鹿島建設プログラミングコンテスト2024(AtCoder Beginner Contest 340)
G
Leaf Color
AtCoder
⌀ 2401
原题
翻译中…

Problem Statement

翻译中…

There is a tree $T$ with $N$ vertices numbered from $1$ to $N$. The $i$-th edge connects vertices $u_i$ and $v_i$. Additionally, vertex $i$ is painted with color $A_i$. Find the number, modulo $998244353$, of (non-empty) subsets $S$ of the vertex set of $T$ that satisfy the following condition:

翻译中…
  • The induced subgraph $G$ of $T$ by $S$ satisfies all of the following conditions:
  • $G$ is a tree.
    • All vertices with degree $1$ have the same color.
翻译中…

What is an induced subgraph? Let $S$ be a subset of the vertices of a graph $G$. The induced subgraph of $G$ by $S$ is a graph whose vertex set is $S$ and whose edge set consists of all edges in $G$ that have both endpoints in $S$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i \leq N$
  • $1 \leq u_i \lt v_i \leq N$
  • The graph given in the input is a tree.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \dots A_N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}

翻译中…

Output

翻译中…

Print the number, modulo $998244353$, of (non-empty) subsets $S$ of the vertex set of $T$ that satisfy the condition in the problem statement.

翻译中…

样例

Input #1
3
1 2 1
1 2
2 3
Output #1
4
The following four sets of vertices satisfy the condition. - $\lbrace 1 \rbrace$ - $\lbrace 1, 2, 3 \rbrace$ - $\lbrace 2 \rbrace$ - $\lbrace 3 \rbrace$
Input #2
5
2 2 1 1 1
2 5
3 4
1 3
1 5
Output #2
9
Input #3
15
5 3 5 1 1 4 4 4 2 5 5 4 4 2 5
3 13
4 10
7 11
8 9
2 10
2 14
5 11
5 6
6 13
12 13
9 14
9 13
1 13
1 15
Output #3
48
题目信息
题号
abc340_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。