#P7727. 风暴之眼(Eye of the Storm)
风暴之眼(Eye of the Storm)
Background
With Moon Island, the king crab, and the celestial detector, you have successfully assembled three pieces of celestial technology. Next, what you need to do is to reach the center of the Eye of the Storm and prepare for the final step of that mysterious experiment.
The ultimate truth is within reach. Can you pass this trial successfully?
Problem Description
The weather inside a celestial storm changes rapidly.
The roads in the storm form an unrooted tree with nodes. Node has an initial value ( is or ) and a type .
There are two types of nodes: nodes and nodes.
For an node, after each second ends, its value becomes the of its own value and the values of all its neighbors from the previous second.
For an node, after each second ends, its value becomes the of its own value and the values of all its neighbors from the previous second.
Now it is known that from some moment on, the values of all nodes no longer change. Call the value of node at this moment .
You do not know the initial value and type of each node, and you only know the final value of each node. Find how many possible combinations of initial values and types there are. Output the answer modulo .
Input Format
The first line contains an integer , the number of nodes in the tree.
The second line contains integers , representing the final value of each node.
The next lines each contain two integers , describing an edge in the unrooted tree.
Output Format
Output one line with one integer, the number of possible combinations of initial values and types.
2
0 0
1 2
6
Hint
[Sample 1 Explanation]
There are six possible combinations of initial values and types as follows:
-
$((w_1, t_1), (w_2, t_2)) = ((0, \texttt{AND}), (0, \texttt{AND}))$.
-
$((w_1, t_1), (w_2, t_2)) = ((0, \texttt{AND}), (0, \texttt{OR}))$.
-
$((w_1, t_1), (w_2, t_2)) = ((0, \texttt{OR}), (0, \texttt{AND}))$.
-
$((w_1, t_1), (w_2, t_2)) = ((0, \texttt{OR}), (0, \texttt{OR}))$.
-
$((w_1, t_1), (w_2, t_2)) = ((1, \texttt{AND}), (0, \texttt{AND}))$.
-
$((w_1, t_1), (w_2, t_2)) = ((0, \texttt{AND}), (1, \texttt{AND}))$.
[Constraints]
This problem uses bundled testdata.
For of the testdata, , , , and the input is guaranteed to form a tree.
| Subtask ID | Points | Special Constraints | |
|---|---|---|---|
| None | |||
| None | |||

Translated by ChatGPT 5