Logo
(追記) (追記ここまで)

30296번 - HLD 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB42121038.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.

제한

  • 2ドル \le N \le 100,000円$
  • 1ドル \le Q \le 100,000円$
  • 1ドル \le x_i, y_i \le N,ドル $x_i \neq y_i$ $(1 \le i \le N-1)$
  • It is guaranteed that the given edges form a tree.
  • 1ドル \le s, e \le N,ドル $s \neq e$
  • 1ドル \leq k \leq 10^9$
  • All values in the input are integers.

예제 입력 1

3 3
1 2
3 1
1 3 2
1 3 3
1 2 2

예제 출력 1

0
0
2

예제 입력 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

예제 출력 2

0
0
0
0
0

예제 입력 3

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

예제 출력 3

0
1
7
12
14
15
23
26

예제 입력 4

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

4
8
15
15
15
19
19
25
28
28

예제 입력 5

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

예제 출력 5

9
9
9
21
23
25
27
33
33
38

예제 입력 6

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

예제 출력 6

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번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /