#D33. Tousa Tree
Tousa Tree
Tousa Tree
Problem
You were asked by your friend Tousa the day before yesterday. He wants to decorate a tree with an arithmetic progression and use it for a birthday party, but the tree is too big to be used alone. Therefore, he wants you, an excellent programmer, to write a program that efficiently decorates a tree with arithmetic progressions. You and Tousa are old friends. You decide to accept Tousa's request.
You will be given a tree of nodes to decorate. The nodes of the tree are numbered from to . Initially, all tree nodes score . The program must respond to the following two queries:
- . Finds the sum of the points written on the nodes of the specified section of the tree.
- . Adds an arithmetic progression to the nodes in the specified section of the tree.
Beautifully decorate the trees to celebrate Tousa's birthday.
Constraints
The input satisfies the following conditions.
- All inputs are integers
Input
The input is given in the following format.
:: ::
The number of nodes in the tree and the number of queries are given in the row. Then the line is given information about the edges of the tree. , indicate that there is an edge directly between the nodes and . After that, instructions are given.
The format of is as follows.
and are vertex numbers. The interval is specified by two nodes. This is the interval in which the shortest route from to is specified. Report the sum of the points written on the nodes included in the interval. However, and are also included in the interval. The answer can be very large, so print out the remainder divided by .
As above, add points to the nodes included in the interval specified by and . The points to be added are calculated as follows, assuming that the shortest distance from is .
Output
When querying , the sum of the points written in the nodes included in the specified interval is output in one line.
Examples
Input
3 3 0 2 1 2 1 1 0 0 1 0 0 2 0 0 1
Output
3 3
Input
5 6 1 0 2 0 3 2 4 1 1 1 4 0 4 0 4 1 1 3 0 7 3 0 2 2 1 4 1 8 0 0 4 2
Output
4 10 43
inputFormat
input satisfies the following conditions.
- All inputs are integers
Input
The input is given in the following format.
:: ::
The number of nodes in the tree and the number of queries are given in the row. Then the line is given information about the edges of the tree. , indicate that there is an edge directly between the nodes and . After that, instructions are given.
The format of is as follows.
and are vertex numbers. The interval is specified by two nodes. This is the interval in which the shortest route from to is specified. Report the sum of the points written on the nodes included in the interval. However, and are also included in the interval. The answer can be very large, so print out the remainder divided by .
As above, add points to the nodes included in the interval specified by and . The points to be added are calculated as follows, assuming that the shortest distance from is .
outputFormat
Output
When querying , the sum of the points written in the nodes included in the specified interval is output in one line.
Examples
Input
3 3 0 2 1 2 1 1 0 0 1 0 0 2 0 0 1
Output
3 3
Input
5 6 1 0 2 0 3 2 4 1 1 1 4 0 4 0 4 1 1 3 0 7 3 0 2 2 1 4 1 8 0 0 4 2
Output
4 10 43
样例
5 6
1 0
2 0
3 2
4 1
1 1 4 0 4
0 4 1
1 3 0 7 3
0 2 2
1 4 1 8 0
0 4 2
4
10
43
</p>