K Network Stations
면접 대비시간 제한2초메모리 제한1024 MB
가중치 트리를 K개의 연결된 영역으로 나눌 때 각 영역 내 모든 건물 쌍의 거리 합의 최댓값을 최소로 만드는 값을 구한다.
문제
The city of “문해프” consists of buildings and roads, forming a tree structure (meaning that every pair of buildings is connected by exactly one simple path, and there are no cycles.). All roads are bidirectional and have their own lengths.
The newly appointed mayor of “문해프” City plans to divide the city into regions by removing roads. (if , a single region covers the entire city.) Then, one Network Station will be built in each region to facilitate communication among the buildings within that region.
Each region contains multiple buildings. The communication complexity of region is defined as , where the sum runs over all unordered pairs of distinct buildings in . In other words, the communication complexity of a region is the total sum of distances between all pairs of buildings in that region.
The mayor of “문해프” City wants to minimize the maximum communication complexity among all regions. Find the minimum possible value of this maximum communication complexity when the city is divided optimally.
입력
The first line contains two integers and , the number of buildings and the number of regions to divide the city into.
Each of the next lines contains three integers , , and , indicating that there is a bidirectional road between buildings and with length .
It is guaranteed that the given graph forms a tree.
출력
Print a single integer: the minimum possible value of the maximum communication complexity among all regions.