No.900 aδδitivee
問題文最終更新日: 2019-10-04 22:04:13
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 226 (木上クエリコン)
(順位表)
の他の問題:
Problem Statement
niuez has created an additive that makes trees grow, so he decided to try out its power.
However, since it would be dangerous if a tree grew to an unimaginable size, he decided to run a simulation beforehand.
There is a directed tree with $N$ vertices numbered from $0$ to $N-1$ and $N-1$ edges, rooted at vertex $0$. The $i \ (0 \leq i < N-1)$-th edge of the tree goes from vertex $u_i$ to vertex $v_i$ and has weight $w_i$.
Process the following $Q$ queries ${\rm query}$ in order.
-
$1 \ a \ x$
- ${\rm query}\ 1$: Add $x$ to the weights of all edges contained in the subtree of vertex $a$.
-
$2 \ b$
- ${\rm query}\ 2$: Find the sum of the weights of the edges contained in the path from vertex $0$ to vertex $b$.
Input
$N$
$u_0 \ v_0 \ w_0$
$\cdots$
$u_{N-2} \ v_{N-2} \ w_{N-2}$
$Q$
${\rm query}_0$
$\cdots$
${\rm query}_{Q-1}$
- $2 \leq N \leq 10^5$
- $0 \leq u_i, v_i < N$
- $u_i \neq v_i$
- $(u_i, v_i) = (u_j, v_j) \Leftrightarrow i = j$
- $0 \leq w_i \leq 10^5$
- $1 \leq Q \leq 10^5$
- ${\rm query}_i$ is in one of the following formats.
-
$1 \ a \ x $
- $0 \leq a < N$
- $0 \leq x \leq 10^5$
-
$2 \ b$
- $0 \leq b < N$
-
- All input values are integers.
Output
Print the answers to ${\rm query}\ 2$ in order, separated by newlines.
Sample
Sample 1
Input
7 0 1 1 0 2 2 1 3 3 1 4 4 2 5 5 2 6 6 7 2 3 2 5 1 2 100 2 5 2 6 1 0 1000 2 6
Output
4 7 107 108 2108
Sample 2
Input
10 0 7 1 1 5 4 2 9 4 0 8 3 1 2 10 0 1 6 0 3 3 0 6 0 2 4 10 10 2 0 1 2 8 2 7 2 9 1 1 5 1 0 4 2 0 2 4 2 9 2 7
Output
0 1 28 0 56 50 5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Lemma299