#P10912. [蓝桥杯 2024 国 B] 数星星

[蓝桥杯 2024 国 B] 数星星

Problem Description

Xiaoming is counting stars on a tree. This tree has nn nodes 1,2,,n1, 2, \cdots, n. He defines a subgraph GG on the tree to be a star if and only if GG satisfies all of the following:

  1. GG is a tree.
  2. There exists a node in GG whose degree is VG1|V_G| - 1, where VG|V_G| denotes the number of nodes contained in this subgraph.

Two stars are considered different if and only if their node sets VGV_G are not exactly the same. Xiaoming wants to know how many different stars in this tree have a number of nodes within the interval [L,R][L, R]. Output the answer modulo 10000000071000000007.

Input Format

The input has a total of n+1n + 1 lines.

The first line contains a positive integer nn.

The next n1n - 1 lines each contain two positive integers, representing an edge of the tree.

The (n+1)(n + 1)-th line contains two positive integers L,RL, R.

Output Format

Output a total of 11 line, containing one integer representing the answer.

6
1 2
1 3
2 4
2 5
3 6
3 4
6

Hint

Sample Explanation.

There are 55 stars containing 33 nodes, and their node sets are {1,2,3}\{1, 2, 3\}, {1,2,4}\{1, 2, 4\}, {1,2,5}\{1, 2, 5\}, {2,4,5}\{2, 4, 5\}, {1,3,6}\{1, 3, 6\}.

There is 11 star containing 44 nodes, and its node set is {1,2,4,5}\{1, 2, 4, 5\}.

Constraints.

For 20%20\% of the testdata, it is guaranteed that n20n \le 20.
For 100%100\% of the testdata, it is guaranteed that n105n \le 10^5, 1LRn1 \le L \le R \le n.

Translated by ChatGPT 5