#P5007. DDOSvoid 的疑惑
DDOSvoid 的疑惑
Description
Given a rooted tree with root , define a “nasty set” of the tree as a set such that for any two elements in the set, there is no ancestor-descendant relationship between them.
Define the “nasty index” of a nasty set as the sum of the values of all elements in the set. You are asked to compute the sum of the nasty indices of all nasty sets of the given tree, modulo .
But this problem is too hard, so we consider a simplified version.
Because the node numbering is closely related to its nasty index, we will additionally give an integer : when , the value (nasty index contribution) of node is ; when , the value of every node is .
Input Format
The first line contains two integers and , meaning the tree has nodes.
The next lines each contain two integers and , meaning there is an edge connecting and .
Output Format
Output one integer, the answer.
5 0
1 2
2 3
2 4
1 5
16
Hint
Sample Explanation:
The sets are $\{1\},\{2\},\{3\},\{4\},\{5\},\{2,5\},\{3,4\}, \{3,5\},\{3,4,5\},\{4,5\}$.
Constraints and Notes
This problem uses bundled multiple test points.
- For of the points, .
- For another of the points, , .
- For of the data, , .
To help you understand the statement, here is the mathematical definition of a nasty set:
Let a nasty set be . Then:
- , there does not exist a node such that lies on the simple path from to the root, and . Here , and is the vertex set of the tree.
Translated by ChatGPT 5
京公网安备 11011102002149号