luogu#P5007. DDOSvoid 的疑惑
DDOSvoid 的疑惑
Background
DDOSvoid has recently been very obsessed with tree structures, especially the “persistent Pleasant Goat and Big Big Wolf set Red Wolf tree”, which can maintain any information you want in time.
However, this is only a theoretical data structure. In order to study how it can be implemented, DDOSvoid began to think about the relationship between a tree’s parent and children.
If this data structure could be implemented, then there would be no more nasty problems in this world.
But after all, this problem is too hard, so let us first consider the following problem.
Problem 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