| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 5 초 | 1024 MB | 3 | 2 | 2 | 100.000% |
Consider a tree with a green or blue stone placed at each vertex. Such a tree is called a "Gemini Tree" if condition 3 can be satisfied after performing the following operations 1 and 2.
Consider a "Gemini tree" with a specified length for each edge, and define its value as follows.
Note that stones are not moved when calculating the value.
You are given a "Gemini tree" with a specified length for each edge. It has $N$ vertices, where $N$ is an odd number. The $i$-th edge connects two vertices, $u_i$ and $v_i$, and has a length $w_i$. The stone colors placed on vertices represent the string $S = s_1s_2\dots s_N$.
You sequentially perform $Q$ operations on this tree. The $j$-th operation is defined by two integers $e_j$, $a_j$, which represents increasing the length of the $e_j$-th edge by $a_j$. The effect of the operation remains even in subsequent operations. Answer the value of the tree after each operation.
$N$
$s_1s_2 \dots s_N$
$u_1$ $v_1$ $w_1$
$\vdots$
$u_{N-1}$ $v_{N-1}$ $w_{N-1}$
$Q$
$e_1$ $a_1$
$\vdots$
$e_Q$ $a_Q$
Output the answer in $Q$ lines. On the $j$-th line, output the value of the tree after the $j$-th operation. Add a new line at the end of each line.
5 GBBBB 1 2 0 1 3 0 2 4 0 2 5 0 5 1 1 2 3 3 3 4 10 2 2
0 1 1 3 4
5 BGBGB 1 2 0 1 3 0 2 4 0 2 5 1000 4 4 1 3 1 1 1 2 1
0 1 3 4
7 GGGBBBB 1 5 1 2 5 1 7 5 0 7 6 0 3 6 0 4 6 0 6 5 1 5 1 5 1 6 3 3 3 5 100000
1 2 2 3 6 11
In Sample Input 1, there is one green stone. Therefore, the problem is to move this to one of the leaves at a minimal cost.