Subway Stations
시간 제한1.5초메모리 제한1024 MB
가중치가 있는 트리에서 노드 K개 이하의 단순 경로를 골라, 모든 노드에서 가장 가까운 선택 노드까지의 거리 최댓값을 최소화한다.
문제
Seoul City Mayor Hanbyeol plans to build a subway system to alleviate traffic congestion on its jam-packed roads. However, due to budget constraints, only a maximum of stations can be built, and a single path of roads must connect all the stations.
Specifically, when the layout of Seoul can be represented as a connected graph with nodes and bidirectional edges, where a node represents a building and an edge represents a road, Hanbyeol must select a simple path of nodes, where , and build stations on every node along that path.
Hanbyeol wants to minimize the maximum distance between the buildings to the nearest station. To help Hanbyeol, write a program that determines the best location for the subway stations so that such value is minimized.
입력
The first line of input contains two space-separated integers: , denoting the count of the nodes in the city, and , denoting the count of the maximum subway stations that Hanbyeol can build. ()
The -th of the next lines of input contains three space-separated integers: and , denoting the indices of nodes that the -th road is connecting, and , denoting the length of the -th road in kilometers. ( )
출력
Output the maximum distance from any building to the nearest subway station when it is the minimum possible, in kilometers.
힌트
(For Sogang students:) Note that this problem is an improvised version that matches the format of a problem in a general programming contest. While in the exam, the original scoring was:
- points for Subtask 1.
- points for Subtask 2.
- points for Subtask 3.
- points for Subtask 4.