#P5021. Maximize the Minimum Track Length

    ID: 18259 Type: Default 1000ms 256MiB

Maximize the Minimum Track Length

Maximize the Minimum Track Length

C City is about to host a series of car races. Before the races, m racing tracks must be built in the city. The city has n intersections numbered from 1 to n and there are n-1 bidirectional roads suitable for constructing race tracks. The i-th road links intersections a_i and b_i and has a length of l_i. It is guaranteed that any intersection can reach any other intersection via these roads.

A track is defined as a sequence of distinct roads \(e_1, e_2, \dots, e_k\) such that one can start at some intersection and traverse these roads sequentially (each road used exactly once and without turning back) to reach another intersection. The length of a track is the sum of the lengths of the roads it passes. For safety reasons, each road can be used in at most one track.

Your task is to design a scheme to build m tracks such that the minimum length among the m tracks is maximized. In other words, if the lengths of the tracks are \(L_1, L_2, \dots, L_m\), you should maximize \(\min\{L_1,L_2,\dots,L_m\}\).

Input Constraints: The input always describes a tree, i.e. a connected graph with exactly n-1 roads.

inputFormat

The first line contains two integers n and m (\(2 \le n \le 10^5\), \(1 \le m \le n-1\)), representing the number of intersections and the number of tracks to build.

Each of the next n-1 lines contains three integers a_i, b_i and l_i (\(1 \le a_i, b_i \le n\), \(1 \le l_i \le 10^9\)), indicating that there is a road connecting intersections a_i and b_i with length l_i.

outputFormat

Output a single integer representing the maximum possible value of the minimum track length among the m tracks.

sample

3 1
1 2 3
2 3 4
7