| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 5 초 (추가 시간 없음) | 1024 MB | 42 | 12 | 10 | 38.462% |
You are given a rooted tree consisting of $N$ vertices. Its root is vertex 1ドル$. Let's consider about a heavy-light decomposition of a tree, where each edge is either a heavy edge or a light edge. For each vertex, among all edges connecting the vertex with its children, at most one edge can be a heavy edge.
In this problem, we have a multiset of simple paths $T,ドル which is initially empty. We will assign each edge to be a heavy edge or a light edge according to $T,ドル satisfying the condition above.
Each time a update is done on $T,ドル your task is to find an assignment of edges that minimizes the sum of the number of light edges of all paths in $T$.
$Q$ updates are given in total. Each query consists of three integers $s,ドル $e,ドル and $k,ドル meaning $k$ copies of the simple path from $s$ to $e$ are inserted into $T$. Find the minimum sum of the number of light edges of all paths in $T$ after each update.
The first line contains two space-separated integers $N, Q$.
The $i$-th of the following $N-1$ lines contains two space-separated integers $x_i$ and $y_i,ドル meaning that the $i$-th edge connects vertices $x_i$ and $y_i$ in the tree.
The $i$-th of the following $Q$ lines contains three space-separated integers $s,ドル $e,ドル and $k,ドル describing each update.
The update are processed in the input order, and result of each update is accumulated.
Print the answer after each update in $Q$ lines.
3 3 1 2 3 1 1 3 2 1 3 3 1 2 2
0 0 2
5 5 3 4 2 4 1 2 5 3 5 4 2 1 2 4 3 4 1 5 3 4 1 2 2
0 0 0 0 0
8 8 4 6 8 4 1 6 5 1 2 1 3 2 7 3 2 7 1 8 2 1 5 3 6 8 3 5 1 4 2 6 7 1 5 6 4 6 2 3
0 1 7 12 14 15 23 26
8 10 8 2 7 8 1 2 4 2 5 1 6 2 3 7 4 5 4 7 2 5 5 8 7 1 3 7 3 2 3 6 8 4 7 3 4 6 7 6 4 8 3 1 3 2
4 8 15 15 15 19 19 25 28 28
10 10 9 7 1 7 5 7 3 9 10 3 8 1 4 7 2 8 6 9 4 9 9 9 3 2 1 9 8 5 4 6 1 5 2 3 5 2 5 6 1 3 5 6 2 8 5 2 1 5
9 9 9 21 23 25 27 33 33 38
15 16 8 1 14 1 3 14 4 1 6 3 12 3 13 1 10 8 15 8 9 8 2 12 5 4 7 15 11 8 3 8 1 11 5 5 13 14 9 15 11 9 11 9 2 14 12 5 12 2 8 10 7 6 11 4 4 13 15 8 4 14 8 11 6 6 3 12 9 7 10 2 2 3 8 13 5 9
1 6 20 29 31 31 31 43 51 64 80 94 95 99 99 115
University > KAIST > KAIST ICPC Mock Competition > 2023 KAIST 13th ICPC Mock Competition E번
Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 2: K-ontest E번