kitten

Time limit: 0.5s Memory limit: 256MB Input: Output:

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 NN- 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 it asks for your help. Write the program kitten to find the smallest possible diameter that can be achieved by doing at most KK operations

Input data

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 data

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

Restrictions

  • 1N21051 \leq N \leq 2 \cdot 10^5
  • 0K1090 \leq K \leq 10^9
  • 1ui,viN1 \leq u_i, v_i \leq N
  • 1wi1041 \leq w_i \leq 10^4
Subtask Points Required subtasks NN KK wiw_i
1 5 - 2 000\leq 2 \ 000 =0= 0 104\leq 10^4
2 5 11 2105\leq 2 \cdot 10^5 =0= 0 104\leq 10^4
3 8 - 2105\leq 2 \cdot 10^5 =1= 1 104\leq 10^4
4 22 - 200\leq 200 109\leq 10^9 =1= 1
5 15 44 2 000\leq 2 \ 000 109\leq 10^9 =1= 1
6 15 454-5 2105\leq 2 \cdot 10^5 109\leq 10^9 =1= 1
7 10 464-6 2105\leq 2 \cdot 10^5 109\leq 10^9 i=1N1wi106\sum_{i=1} ^{N-1} w_i \leq 10^6
8 20 171-7 2105\leq 2 \cdot 10^5 109\leq 10^9 104\leq 10^4

Example 1

stdin

5 6
1 2 5
2 3 4
2 4 3
4 5 2

stdout

6

Explanation

Illustration of the tree and its diameter in the beginning:

After 55 operations we can obtain tree with diameter 66, which is the smallest possible diameter even after 66 operations:

Example 2

stdin

5 7
1 2 5
2 3 4
2 4 3
4 5 2

stdout

5

Example 3

stdin

5 0
1 2 5
2 3 4
2 4 3
4 5 2

stdout

10

Log in or sign up to be able to send submissions!