No.235 Meguru Goes Around (5)
タグ : / 解いたユーザー数 89
作問者 :
LayCurse
Problem Statement
Charo, Senpai.
I finally bought the latest VR game, "Ambition of the yukicoder Kingdom"!
For summer vacation, I, Meguru, am planning to travel around the yukicoder Kingdom several times, so I intend to hole up in a dungeon for now and earn my travel money.
Senpai, please calculate how much I need to earn!
The yukicoder Kingdom has $N$ towns and $N-1$ roads, you see.
The $k$-th road connects town $A_k$ and town $B_k$, and every town can be reached from every other town by passing through some roads.
Each of my trips goes from some town $X$ to some town $Y$ by road, and I plan to stay one night and go sightseeing in every town I visit, including towns $X,Y$.
Right now, staying in town $k$ costs $S_k$, but King yuki has parades scheduled this summer vacation, so the lodging costs are going to change...
Each town $k$ has a value called the inflation coefficient, $C_k$.
When the king holds a parade of scale $Z$ from town $X$ to town $Y$, the lodging costs of the towns the parade passed through, including towns $X,Y$, go up and stay that way from then on.
What's more, each one goes up by that town's inflation coefficient multiplied by $Z$, which is really harsh...
Between now and the end of summer vacation, there are $Q$ scheduled events in total, counting my trips and the parades.
I've labeled them in chronological order as event $1$, event $2$, $\ldots$, event $Q$, and each one is written in my notes in one of the following formats!
- $0\ X\ Y\ Z$: The king's parade of scale $Z$ is held from town $X$ to town $Y$.
- $1\ X\ Y$: Meguru plans to travel from town $X$ to town $Y$!
By the way, King yuki's parades are really gorgeous and fun, you know.
Would you like to go see one with me sometime?
Uh..., right, I guess not...
Input
$N$
$S_1$ $S_2$ $\cdots$ $S_N$
$C_1$ $C_2$ $\cdots$ $C_N$
$A_1$ $B_1$
$A_2$ $B_2$
$\quad \vdots$
$A_{N-1}$ $B_{N-1}$
$Q$
予定 $1$
予定 $2$
$\quad \vdots$
予定 $Q$
Here, event $k$ is in one of the following formats:
$0$ $X_k$ $Y_k$ $Z_k$
or
$1$ $X_k$ $Y_k$
That's all!
$2 \leq N \leq 200000 = 2 \times 10^5$
$0 \leq S_k, C_k \leq 1000000006 = 10^9+6$
$1 \leq A_k, B_k \leq N, \;\; A_k \neq B_k$
$1 \leq Q \leq 200000 = 2 \times 10^5$
$1 \leq X_k, Y_k \leq N, \;\; X_k \neq Y_k$
$0 \leq Z_k \leq 1000000006 = 10^9+6$
Output
For each trip event, please output the lodging cost needed for that trip, assuming everything goes as scheduled, modulo ${\rm mod}\ 1000000007$!
Sample
Sample 1
Input
8 1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 6 1 1 5 1 3 2 7 2 1 2 4 8 4 6 1 1 7 1 8 5 0 6 3 100 1 5 3 0 7 5 10000 1 6 8
Output
10 20 1409 151121
At first, the lodging costs of towns $1$ to $8$ are $1,2,3,4,5,6,7,8$!
When I first travel $1 \to 2 \to 7$, the lodging cost is $1+2+7$, which is $10$, I guess...
The next trip is $8 \to 4 \to 2 \to 1 \to 5$, so it's $8+4+2+1+5$, which is $20$!
After that, the king's parade goes $6 \to 1 \to 3$, so the lodging costs change to $801,2,603,4,5,306,7,8$, I guess...
The trip after that is $5 \to 1 \to 3$, so the lodging cost is $5+801+603$, which is $1409$, I guess...
After that, the king's parade goes $7 \to 2 \to 1 \to 5$, so the lodging costs change to $80801,70002,603,4,40005,306,20007,8$, I guess... They do change, don't they......
The last trip is $6 \to 1 \to 2 \to 4 \to 8$, so it's $306+80801+70002+4+8$, which is $151121$............
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。