#P5007. Tree Tumor Set Sum

    ID: 18245 Type: Default 1000ms 256MiB

Tree Tumor Set Sum

Tree Tumor Set Sum

Given a rooted tree with root 11, we define a tumor set as a set of vertices in which no two vertices have an ancestor–descendant relationship. The tumor index of a tumor set is defined as the sum of the values of all vertices in that set.

The task is to calculate the sum of the tumor indices over all tumor sets of the tree, modulo 100,000,007100{,}000{,}007.

To simplify the problem, an integer TT is provided which affects the value assigned to each vertex.

  • If T=1T = 1, then the value of vertex ii is ii.
  • If T=0T = 0, then every vertex has a value of 11.

Note: The empty set is considered a valid tumor set (its index is 00).

inputFormat

The first line contains two integers n and T.

Each of the following n-1 lines contains two integers u and v, denoting an edge of the tree.

The tree is rooted at vertex 1.

outputFormat

Print the result modulo 100,000,007.

sample

1 0
1