#P11032. 『DABOI Round 1』Develop a Tree
『DABOI Round 1』Develop a Tree
Background
Little Z cannot stand trees, so he always wants to randomly add some edges to a tree. He thinks bipartite graphs are very harmonious, so he wants to know how many ways there are to turn a tree into a bipartite graph. Can you answer his query?
Problem Description
For an undirected rooted tree, define as the number of ways, within the subtree rooted at , to add edges inside it so that this subtree becomes a bipartite graph. Note that when adding edges, it is allowed to add an edge parallel to an original tree edge, but any two newly added edges must not be identical.
Given an undirected rooted tree with nodes, where the root is node . For each , compute .
Input Format
The input has lines.
Line contains two integers and , representing the number of nodes in the tree and the parameter .
Lines to each contain two positive integers, representing an edge between nodes and .
Line contains integers, representing the modulus for each query.
Output Format
Output one line containing integers, each being the answer for the corresponding query.
6 1
1 3
1 5
1 6
2 5
3 4
998244353 998244353 998244353 998244353 998244353 998244353
9 0 1 0 1 0
Hint
[Sample 1 Explanation]
In this tree, adding edges $(u,v)\in\{(1,3),(1,5),(1,6),(2,3),(2,5),(2,6),(3,4),(4,5),(4,6)\}$ can make the tree bipartite.
[Constraints]
This problem uses bundled testdata.
For of the testdata: , , , , and is a prime. There are at most distinct values of . It is guaranteed that .
- : it is guaranteed that .
- : it is guaranteed that .
[Hint]
The amount of I/O in this problem is large, so please use a faster I/O method.
Translated by ChatGPT 5