408405: GYM103114 I Iahaxiki's journey II - enjoying

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Iahaxiki's journey II - enjoyingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Fahaxiki got the opportunity to participate in live competitions through an online competition, and will go to the beautiful Wuhan University to participate in the game. Although they traveled at their own expense on the weekend, they didn't want to miss the opportunity of this trip, so they ask you to help them calculate some problems so that they can get a better travel experience.

In order to simplify the problem, we abstract the developed traffic in Wuhan into some weighted undirected edges, connecting the whole Wuhan into a tree. Find the length of the longest simple path containing k nodes in this tree. A simple path means that the vertices on the path do not overlap with each other.

Input

The first line contains two integers $$$n, k (1 \leq n, k \leq 10^5)$$$, and $$$k$$$ doesn't exceed diameter of the tree.

Then next $$$n - 1$$$ lines, each lines contains three integers $$$a, b, c(1 \leq a, b \leq n, 1 \leq c \leq 10^3)$$$, denote there is an edge between $$$a, b$$$ and length is $$$c$$$.

Output

Output the length of the requested path

ExampleInput
4 3
3 4 45
2 3 89
3 1 18
Output
134

加入题单

上一题 下一题 算法标签: