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

27355번 - Paths 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.3 초 1024 MB139151512.097%

문제

Orange the Cat found a tree (an undirected connected acyclic graph) with $N$ vertices numbered from 1ドル$ to $N$. On each edge $i$ (1ドル ≤ i < N$) connecting vertices $x_i$ and $y_i$ there are $c_i$ special cat treats.

Orange can choose exactly $K$ vertices, walk from the root of the tree to each of the chosen vertices along the paths from the root to the respective vertices and take all the cat treats along those paths. Of course, he can only take the treats on each edge once. Because Orange is a curious cat, he wants to know the maximum possible number of treats he could take by choosing the $K$ vertices optimally, if the root of the tree were vertex $i,ドル for each $i$ from 1ドル$ to $N$.

입력

The first line of the input contains two integers $N$ and $K,ドル the number of vertices of the tree and the number of vertices Orange will choose, respectively. The next $N - 1$ lines contain three integers each, $x_i,ドル $y_i$ and $c_i,ドル describing the edges of the tree.

출력

On line $i$ for 1ドル ≤ i ≤ N$ output the maximum number of treats Orange could take if the root of the tree were vertex $i$.

제한

  • 1ドル ≤ K ≤ N ≤ 100,000円$
  • 0ドル ≤ c_i ≤ 1,000円,000円,000円,ドル for 1ドル ≤ i < N$

서브태스크

번호배점제한
18

$N ≤ 18$

211

$N ≤ 200,ドル $K ≤ 20$

317

$N ≤ 1,000円,ドル $K ≤ 100$

420

$N ≤ 2,000円$

512

$K = 1$

632

No further restrictions

예제 입력 1

11 3
1 2 5
2 3 3
2 6 5
3 4 4
3 5 2
1 7 6
7 8 4
7 9 5
1 10 1
10 11 1

예제 출력 1

28
28
28
32
30
32
28
32
32
29
30

힌트

If the root is vertex 1ドル,ドル then Orange can choose vertices 4ドル,ドル 6ドル$ and 9ドル$. The paths from the root to the chosen vertices are 1ドル − 2 − 3 − 4,ドル 1ドル − 2 − 6,ドル 1ドル − 7 − 9$ and the number of treats along those paths is 5ドル + 3 +たす 4 +たす 5 +たす 6 +たす 5 = 28$. Note that the treats on edge 1ドル − 2$ are only counted once.

출처

Olympiad > Romanian Master of Informatics > Romanian Master of Informatics 2021 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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