NOI Contest Archive

Archive / 2025 / Final Round — Day 2

The Crown Hub

Medium · National Olympiad in Informatics 2025 day 2

In the majestic kingdom of Graphoria, there are n cities connected by n - 1 bidirectional roads, forming a vast network of paths through mountains, rivers, and valleys. Each road has a toll cost, and each city has a population eagerly awaiting the grand Royal Unity Festival — where all citizens must travel to a single city to celebrate.

To host this historic event, the King will designate one city as the Crown Hub, where all citizens must gather. However, travel isn’t cheap: every citizen must pay a cost equal to the sum of tolls along their route to the hub, multiplied by the number of people in their city.

Luckily the king is blessed with a divine favor.He may select up to k cities (excluding the hub) to serve as Divine Reimbursement Centers. These cities grant a magical effect:

The King wants to know the best city to declare as the Crown Hub, and which Reimbursement Center to build, so that the total travel cost for all citizens in the kingdom is minimized.

Input Format

n k
p₁ p₂ ... pₙ

Next n - 1 lines follow:
u v c
...

Output Format

min_total_burden

A single integer: the minimum total burden after optimally choosing the hub and up to K Reimbursement Centers.

Constraints

Subtasks

Sample Input 0

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

Sample Output 0

10