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 nodes and 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 operations. For each operation he picks an edge in the tree that has non-zero length and then he decreases it by . Kis is just a small kitten so he asks for your help. Write the program to find the smallest possible diameter that can be achieved by doing at most operations.
Input Format
The first line of the standard input contains the integers and . Then each of the last contains positive integers: describing an edge between nodes and of length .
Output Format
Output one integer -- the smallest possible diameter of the tree that can be achieved after at most 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
- ;
- ;
- ;
- .
Subtasks
| Subtask | Points | Required subtasks | |||
|---|---|---|---|---|---|
| ^ | |||||
| ^ | |||||
| ^ | |||||
| ^ | |||||
The points for a subtask are given only if all tests for it and the required subtasks are passed successfully.