3872: Sindar's Art Exhibition

内存限制:128 MB 时间限制:3.000 S
评测方式:文本比较 命题人:
提交:13 解决:0

题目描述

Sindar is an excellent artist and she has many works. One day she decides to hold an exhibition tour in her country. Her country is a tree, the nodes of which are the cities and the edges between the nodes are the roads between cities. 
The value of an exhibition are determined by the number of works on the exhibition and the citizens' favorability of art. Generally speaking, if there are m works in the exhibition, and the citizens' favorability is k, then the value of the exhibition will be m∗k
Her tour will begin at city s and end in city t. She will begin the tour with x works, but after she holds the exhibition in every city, she will choose yi suitable works and donate them to the local orphanage, which means that there will be only x−yi works when she holds the next exhibition, and x−yi−yj works in the exhibition after the next, supposing that she will pass city j after city i.
Now she has many tours and she want to know every tour's value mod 109+7. And sometimes she may change one city's favorability.

输入

There are multiple test cases. The first line of the input contains an integer T, indicating the number of test cases. For each test case:
The second line contains one interger n, indicating the number od cities. (1≤n≤105)
It's guaranteed that Σn≤3∗105
The next line contains n interger fi, the i−th interger indicates the citizens' favorability of art in city i.(0≤fi≤2∗109)
The next line contains n interger yi, the i−th interger indicates the number of works Sindar will donate to the orphanage in city i.(0≤yi≤104)
Each of the following n−1 lines contains two intergers u,v indicating that there is a road between city u and city v. (1≤u,v≤n)
The next line contains two interger q,indicating the number of tours and the number of works Sindar will donate to the local orphanage.(1≤q≤105)
Each of the next q lines contains one instruction. And there are two kinds of instructions:
1 s t x indicates the start city ,the end city and the number of works Sindar owns at first. (1≤s,t≤n,s≠t,x≤2∗109)
2 c v indicates Sindar wants to change the favorability of city c to v.(1≤c≤n,0≤v≤2∗109)
It is guaranteed that x≥dis(s,t)∗ydis(s,t) indicates the number of cities you must pass from s to t.

输出

For each query, output one interger indicates the tour's value mod 109+7

样例输入 复制

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

样例输出 复制

129

提示

Hint
129=6*10+5*8+2*6+1*5+3*4

来源/分类