NOI '22 Multi-Provincial Team Selection P2 - Tree

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem type

Tommy has an unrooted tree of n nodes numbered 1,2,,n. He wishes to assign weights to all nodes on some nonempty path on this tree such that the weight wi of a node i on this path satisfies liwiri for given [l1,r1],[l2,r2],,[ln,rn]. Tommy has a positive integer K and further requests that the maximum absolute difference of the weight of any two nodes on this path is less than or equal to K.

  1. How many such assignments satisfy these constraints?
  2. What is the sum of the sum of the weights over all such assignments?

Output the answer modulo 109+7.

Constraints

1n200

1liri109

1K109

70% of points are awarded for the first question and 30% of points are awarded for the second question.

Test n ri,K Properties
1 5 10 None
2-3 30 109 None
4 30 500 None
5-6 200 2×105 None
7-8 200 109 For 1i<n, there is an edge between i and i+1.
9-10 200 109 None

Input Specification

The first line contains two integers n,K.

The i-th of the following n lines contains two integers li,ri.

The following n1 lines describe the edges of the tree.

Output Specification

On the first line, output the answer for the first question.

On the second line, output the answer for the second question.

Please output exactly two integers, as otherwise your submission could be graded as Presentation Error.

Sample Input

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

Sample Output

Copy
14
78

Attachments


Comments

There are no comments at the moment.