F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sindar's Art Exhibition

Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 295    Accepted Submission(s): 76


Problem Description
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 $y_i$ suitable works and donate them to the local orphanage, which means that there will be only $x-y_i$ works when she holds the next exhibition, and $x-y_i-y_j$ 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 $10^9+7$. And sometimes she may change one city's favorability.
 

Input
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\leq n \leq 10^5)$
It's guaranteed that $\Sigma n\leq 3*10^5$
The next line contains $n$ interger $f_i$, the $i-th$ interger indicates the citizens' favorability of art in city $i$.($0\leq f_i\leq 2*10^9)$
The next line contains $n$ interger $y_i$, the $i-th$ interger indicates the number of works Sindar will donate to the orphanage in city $i$.$(0\leq y_i\leq 10^4)$
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\leq u,v \leq 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\leq q \leq 10^5)$
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\leq s,t\leq n , s\neq t,x\leq 2*10^9)$
$2\ c\ v$ indicates Sindar wants to change the favorability of city $c$ to $v$.$(1\leq c\leq n,0\leq v\leq 2*10^9)$
It is guaranteed that $x \geq dis(s,t)*y$. $dis(s,t)$ indicates the number of cities you must pass from $s$ to $t$.
 

Output
For each query, output one interger indicates the tour's value mod $10^9+7$
 

Sample Input
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
 

Sample Output
129
 

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

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 23:23:34, Gzip enabled