#P16961. [SCCPC 2026] 永恒的奥古斯都
[SCCPC 2026] 永恒的奥古斯都
Problem Description
There is a tree with nodes, rooted at node . Initially, node has color ().
Little L performed several (possibly ) operations. In each operation, she chooses a node such that , and for every node in the subtree of , she performs . After all operations, we obtain a tree , where the color of node becomes .
Now you are given the final tree and the color of each node. You need to compute how many different possible initial states there could be. Output the answer modulo .
In this problem, we consider two trees to be different if and only if there exists a node such that its color in is , its color in is , and .
Input Format
The first line contains a positive integer (), indicating the number of nodes in .
The second line contains integers (), representing the color of each node in the final state.
The next lines each contain two positive integers (, ), indicating that there is an edge in . 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 modulo .
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