Logo
(追記) (追記ここまで)

34748번 - K Network Stations 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB138861.538%

문제

The city of “문해프” consists of $N$ buildings and $N - 1$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 $K$ regions by removing $K-1$ roads. (if $K = 1,ドル 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 $R$ contains multiple buildings. The communication complexity of region $R$ is defined as $ \sum_{i,j\in R, i<j} \operatorname{dist}(i,j) ,ドル where the sum runs over all unordered pairs of distinct buildings in $R$. 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 $N$ and $K,ドル the number of buildings and the number of regions to divide the city into. $(K \leq N \leq 100,000,円 K \in \{1,2\})$

Each of the next $N-1$ lines contains three integers $a_i,ドル $b_i,ドル and $c_i,ドル indicating that there is a bidirectional road between buildings $a_i$ and $b_i$ with length $c_i$. $(1 \leq c_i \leq 100)$

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.

제한

서브태스크

번호배점제한
150

1ドル \leq N \leq 400, K = 1$

210

1ドル \leq N \leq 2,000,円 K = 1$

310

1ドル \leq N \leq 100,000,円 K = 1$

410

$K \leq N \leq 400, K \in \{1,2\}$

510

$K \leq N \leq 2,000,円 K \in \{1,2\}$

610

$K \leq N \leq 100,000,円 K \in \{1,2\}$

예제 입력 1

4 1
2 1 1
2 3 2
2 4 4

예제 출력 1

21

Since $K = 1,ドル Region 1 represents the entire city. The communication complexity of Region 1 is dist(1, 2) + dist(1, 3) + dist(1, 4) + dist(2, 3) + dist(2, 4) + dist(3, 4) = 1 +たす 3 +たす 5 +たす 2 +たす 4 +たす 6 = 21.

This example satisfies the conditions of all subtasks.

예제 입력 2

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

예제 출력 2

6

The communication complexity of Region 1 is dist(1, 2) + dist(1, 3) + dist(2, 3) = 6.

The communication complexity of Region 2 is dist(4, 5) = 3.

In this example, dividing the regions as shown in the figure is optimal, and the answer is max(3, 6) = 6.

This example satisfies the conditions of Subtask 4, 5, and 6.

예제 입력 3

1 1

예제 출력 3

0

The communication complexity of Region 1 is 0.

This example satisfies the conditions of all subtasks.

노트

출처

University > 서강대학교 > CSE4152 문제해결프로그래밍실습 > 2025-2학기 중간고사 코딩 테스트 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /