Problem 2995 --Sindar's Art Exhibition

2995: Sindar's Art Exhibition

"
Time Limit $3$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $0$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
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 mm works in the exhibition, and the citizens' favorability is kk, then the value of the exhibition will be m∗km∗k
Her tour will begin at city ss and end in city tt. She will begin the tour with xxworks, but after she holds the exhibition in every city, she will choose yiyi suitable works and donate them to the local orphanage, which means that there will be only x−yix−yi works when she holds the next exhibition, and x−yi−yjx−yi−yj works in the exhibition after the next, supposing that she will pass city jj after city ii
Now she has many tours and she want to know every tour's value mod 109+7109+7. And sometimes she may change one city's favorability.
There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case: 
The second line contains one interger nn, indicating the number od cities. (1≤n≤105)(1≤n≤105) 
It's guaranteed that Σn≤3∗105Σn≤3∗105 
The next line contains nn interger fifi, the i−thi−th interger indicates the citizens' favorability of art in city ii.(0≤fi≤2∗109)0≤fi≤2∗109) 
The next line contains nn interger yiyi, the i−thi−th interger indicates the number of works Sindar will donate to the orphanage in city ii.(0≤yi≤104)(0≤yi≤104) 
Each of the following n−1n−1 lines contains two intergers u,vu,v indicating that there is a road between city uu and city vv. (1≤u,v≤n1≤u,v≤n
The next line contains two interger qq,indicating the number of tours and the number of works Sindar will donate to the local orphanage.(1≤q≤105)(1≤q≤105) 
Each of the next qq lines contains one instruction. And there are two kinds of instructions: 
1 s t x1 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)(1≤s,t≤n,s≠t,x≤2∗109) 
2 c v2 c v indicates Sindar wants to change the favorability of city cc to vv.(1≤c≤n,0≤v≤2∗109)(1≤c≤n,0≤v≤2∗109) 
It is guaranteed that x≥dis(s,t)∗yx≥dis(s,t)∗ydis(s,t)dis(s,t) indicates the number of cities you must pass from ss to tt.
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
129=6*10+5*8+2*6+1*5+3*4

推荐代码 查看2995 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战

赛题来源/所属竞赛 2019 Multi-University Training Contest 3 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛