#P10773. [NOISG 2021 Qualification] Truck
[NOISG 2021 Qualification] Truck
Problem Description
There is a tree. Each edge has two weights and . You are given operations. There are two types of operations:
0 x y t: change the value of the edge between and to .
1 x y: query the cost from to .
Define the cost from to as follows: given a parameter (the same for all queries), node needs to transport some amount of value to node . Each time it passes an edge with weights and , the transported value decreases by , and then a cost equal to times the current transported value is incurred. When the transport reaches node , if the remaining value is exactly , then the total incurred cost is defined as the cost from to .
You need to compute the cost for each query. Since the cost may be large, output it modulo .
Input Format
The first line contains two integers .
Lines each contain four integers , meaning there is an edge between and in the tree, with edge weights and .
Line contains an integer , the number of operations.
The next lines each contain one operation, in the format described above.
Output Format
Output several lines. For each query operation, you need to output the cost. Print one answer per line.
6 2
1 2 2 1
2 3 1 2
2 4 2 3
4 5 2 2
4 6 1 4
3
1 3 6
0 4 5 5
1 2 5
23
18
4 3
1 2 3 0
2 3 1 0
3 4 4 0
1
1 1 4
24
Hint
Constraints
This problem uses bundled testdata.
Subtask 0 is the sample.
Subtask 1 (5 pts): only query operations, each node degree is at most , and .
Subtask 2 (9 pts): only query operations, and .
Subtask 3 (12 pts): only query operations, , and all are equal.
Subtask 4 (17 pts): only query operations, and each node degree is at most .
Subtask 5 (20 pts): each node degree is at most .
Subtask 6 (18 pts): .
Subtask 7 (19 pts): no special constraints.
It is guaranteed that , , , , and .
Translated by ChatGPT 5