#P15902. [TOPC 2025] Gas Station

[TOPC 2025] Gas Station

Description

Alex is planning rest area placements on a simplified model of Taiwan’s freeway system. The system contains nn interchanges, connected by n1n - 1 bidirectional roads. The network is connected, and there is exactly one shortest route between any pair of interchanges. The ii-th road connects interchanges uiu_i and viv_i, and has a length of lil_i.

Exactly kk rest areas with gas stations can be built, each located at an interchange. A driver may start a trip from any interchange and travel to any other, always following the unique shortest path. They begin each trip with a full tank of gas and can refuel only at interchanges that have a rest area.

Alex is curious about the smallest possible fuel tank capacity dd such that it’s possible to place the kk rest areas in a way that ensures no driver will ever run out of gas. On any trip, the driver must never have to travel more than dd units along the path without passing through a rest area, including at the beginning or end of the journey. The goal is to figure out the minimum such dd, assuming the rest areas are placed in the best possible way.

Input Format

The first line contains two integers n,kn, k.

Followed by n1n - 1 lines, the ii-th of which contains three integers ui,vi,liu_i, v_i, l_i, representing the ii-th road connects interchanges uiu_i and viv_i with a length lil_i.

Output Format

Output one integer, the smallest possible fuel tank capacity dd.

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

Hint

  • 2n2×1052 \le n \le 2 \times 10^5
  • 0kn0 \le k \le n
  • 1ui,vin1 \le u_i, v_i \le n
  • 1li1091 \le l_i \le 10^9
  • It is guaranteed that the input roads form a tree.