시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 50 | 15 | 15 | 41.667% |
You are given a tree $T$ consisting of $N$ vertices. Each edge has a positive integer weight.
You can perform the following operation on the given tree.
We define the weight of a path as the sum of the weights of the edges on the path. The distance between two vertices $u$ and $v$ is defined as the weight of the shortest path from $u$ to $v$ — having the minimum weight. If there is no such path, we define the distance as $0$.
The weight of a graph is the maximum of the distances between any two vertices.
Your task is to find the largest weight of the graph that can be obtained by performing the operation exactly $i$ times, for $i=0,1,\dots ,K$.
The first line contains two space-separated integers, $N$ and $K$.
The $i$-th of the following $N-1$ lines contains three space-separated integers $u_i$, $v_i$, and $w_i$ — representing an undirected edge that connects two different vertices $u_i$ and $v_i$ with a weight of $w_i$.
It is guaranteed that the edges form a tree.
Output $K+1$ space-separated integers. The $i$-th integer should be equal to the largest weight of the graph that can be obtained by performing the operation exactly $i-1$ times.
5 1 1 3 2 4 5 4 3 4 3 2 3 7
14 16
7 2 1 2 4 2 3 6 2 4 2 4 5 5 2 6 1 4 7 3
13 20 21
University > KAIST > 2022 KAIST 12th ICPC Mock Competition F번
Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 4: KAIST+KOI Contest, Grand Prix of Korea G번