#P10773. [NOISG 2021 Qualification] Truck

[NOISG 2021 Qualification] Truck

Problem Description

There is a tree. Each edge has two weights DiD_i and TiT_i. You are given QQ operations. There are two types of operations:

0 x y t: change the TiT_i value of the edge between xx and yy to tt.

1 x y: query the cost from xx to yy.

Define the cost from xx to yy as follows: given a parameter GG (the same for all queries), node xx needs to transport some amount of value to node yy. Each time it passes an edge with weights DiD_i and TiT_i, the transported value decreases by TiT_i, and then a cost equal to DiD_i times the current transported value is incurred. When the transport reaches node yy, if the remaining value is exactly GG, then the total incurred cost is defined as the cost from xx to yy.

You need to compute the cost for each query. Since the cost may be large, output it modulo 109+710^9+7.

Input Format

The first line contains two integers N,GN, G.

Lines 2N2 \sim N each contain four integers Ai,Bi,Di,TiA_i, B_i, D_i, T_i, meaning there is an edge between AiA_i and BiB_i in the tree, with edge weights DiD_i and TiT_i.

Line N+1N+1 contains an integer QQ, the number of operations.

The next QQ 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 22, and Ti=0T_i = 0.

Subtask 2 (9 pts): only query operations, and Ti=0T_i = 0.

Subtask 3 (12 pts): only query operations, Di=1D_i = 1, and all TiT_i are equal.

Subtask 4 (17 pts): only query operations, and each node degree is at most 22.

Subtask 5 (20 pts): each node degree is at most 22.

Subtask 6 (18 pts): N,Q5000N, Q \leq 5000.

Subtask 7 (19 pts): no special constraints.

It is guaranteed that 2N1052 \leq N \leq 10^5, 1Q1051 \leq Q \leq 10^5, 1Ai,BiN1 \leq A_i, B_i \leq N, 1Di,G1091 \leq D_i, G \leq 10^9, and 0Ti1090 \leq T_i \leq 10^9.

Translated by ChatGPT 5