You have a tree on n vertices, and each vertex has a weight av and a degree at most 5.
Let's call the density of a subset of vertices S value ∑v∈Sav|S|, and call the beauty of the tree with some vertices turned off the maximum value of the density of a subset of at least two turned on vertices with connected induced subgraph, or 0 if no such subset exists.
Now you need to calculate the number of ways to choose such a set of turned off vertices among 2n ways that the beauty of the tree is no larger than x, modulo 1000000007.
Let's call the density of a subset of vertices S value ∑v∈Sav|S|, and call the beauty of the tree with some vertices turned off the maximum value of the density of a subset of at least two turned on vertices with connected induced subgraph, or 0 if no such subset exists.
Now you need to calculate the number of ways to choose such a set of turned off vertices among 2n ways that the beauty of the tree is no larger than x, modulo 1000000007.