luogu#P16386. [IATI 2025] Kitten

[IATI 2025] Kitten

Problem Description

:::align{center} Who doesn't love videos with kittens and trees? :::

Kitten Kis has found a big tree in his yard. He wants to climb it, but the tree is too big! The tree he has found has NN nodes and N1N-1 edges. Each edge has a positive length. We define the distance between any two nodes as the sum of the lengths of the edges on a simple path between them. Additionally, we define the diameter of a tree as the biggest distance between any two nodes.

To climb the tree, Kis wants to make the tree diameter as small as possible. In order to achieve this he can do at most KK operations. For each operation he picks an edge in the tree that has non-zero length and then he decreases it by 11. Kis is just a small kitten so he asks for your help. Write the program kitten\textbf{kitten} to find the smallest possible diameter that can be achieved by doing at most KK operations.

Input Format

The first line of the standard input contains the integers NN and KK. Then each of the last N1N-1 contains 33 positive integers: ui vi wiu_i \ v_i \ w_i describing an edge between nodes uiu_i and viv_i of length wiw_i.

Output Format

Output one integer -- the smallest possible diameter of the tree that can be achieved after at most KK operations.

5 6
1 2 5
2 3 4
2 4 3
4 5 2
6
5 7
1 2 5
2 3 4
2 4 3
4 5 2
5
5 0
1 2 5
2 3 4
2 4 3
4 5 2
10

Hint

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5;
  • 0K1090 \leq K \leq 10^9;
  • 1ui,viN1 \leq u_i, v_i \leq N;
  • 1wi1041 \leq w_i \leq 10^4.

Subtasks

Subtask Points Required subtasks NN KK wiw_i
11 55 - 2 000\leq 2~000 =0=0 104\leq 10^4
22 11 2×105\leq 2 \times 10^5 ^
33 88 - ^ =1=1
44 2222 200\leq 200 109\leq 10^9 =1=1
55 1515 44 2 000\leq 2~000 ^
66 454-5 2×105\leq 2 \times 10^5
77 1010 464-6 (Σi=1N1 wi)106(\Sigma_{i=1}^{N-1} \ w_i) \leq 10^6
88 2020 171-7 ^ 104\leq 10^4

The points for a subtask are given only if all tests for it and the required subtasks are passed successfully.