Gas Station

시간 제한3초메모리 제한2048 MB

요약
가중치가 있는 트리의 정점 k곳에 휴게소를 세워, 어떤 경로 구간도 휴게소 없이 지나는 최대 거리를 최소로 만드는 문제입니다.
난이도

어려움10점 중 8점

유형
이분 탐색, 트리, 그리디, DFS
정답자
아직 제출이 없습니다

문제

Alex is planning rest area placements on a simplified model of Taiwan’s freeway system. The system contains nn interchanges, connected by n−1n − 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 u_iu\_i and v_iv\_i, and has a length of l_il\_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.

입력

The first line contains two integer nn, kk.

Followed by n−1n − 1 lines, the ii-th of which contains three integers u_iu\_i, v_iv\_i, l_il\_i, representing the ii-th road connects interchanges u_iu\_i and v_iv\_i with a length l_il\_i.

출력

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

제한

  • 2≤n≤2×1052 ≤ n ≤ 2 \times 10^5
  • 0≤k≤n0 ≤ k ≤ n
  • 1≤u_i,v_i≤n1 ≤ u\_i , v\_i ≤ n
  • 1≤l_i≤1091 ≤ l\_i ≤ 10^9
  • It is guaranteed that the input roads form a tree.

예제2

  1. 예제 1

    입력
    5 1
    1 2 3
    1 5 2
    2 3 3
    2 4 1
    
    예상 출력
    5
    
  2. 예제 2

    입력
    5 2
    1 2 3
    1 5 2
    2 3 3
    2 4 1
    
    예상 출력
    3