#P5793. [CTSC2004] 网络改造

[CTSC2004] 网络改造

Description

Your program must produce output that satisfies the requirements based on the given input:

  • The input includes the network topology, the cost to upgrade each switch in the network, the cost to reconstruct links, and the maximum number pp of switches that can be upgraded.
  • Based on the input, you must find an upgrade plan such that the number of core switches after upgrading does not exceed the given maximum pp, and the total cost is minimized.
  • The total cost consists of two parts:
    • One part is the cost required to upgrade switches to core switches, which is the sum of the upgrade costs of all switches that are upgraded.
    • The other part is the cost required to reconstruct the network, which is the sum of the network path distances from every non-upgraded switch to its nearest core switch.
    • Note: If no switch in the network is upgraded to a core switch, since no switch can be connected to a core switch, we define the total cost in this case to be infinity.

Input Format

The first line contains two positive integers n(n400)n(n \leq 400) and pp, representing the number of switches in the network (switches are numbered from 11 to nn) and the maximum number of switches that can be upgraded.

The next nn lines each contain a positive integer cic_i, representing the cost to upgrade switch ii to a core switch.

The next n1n-1 lines each contain three positive integers ii, jj, and di,j(di,j<20000)d_{i,j}(d_{i,j}<20000), indicating that switch jj is an upper-level switch of switch ii, and di,jd_{i,j} is the network distance between the two switches.

Output Format

The first line of output contains an integer MM, representing the minimum total cost of your plan.

The next line contains an integer p0p_0, representing the number of switches that need to be upgraded to core switches in your plan.

7 2
7
1
7
7
7
1
2
2 1 2
3 2 4
6 5 2
7 5 9
5 1 3
4 1 7
30
2

Hint

Sample Explanation

Scoring Method

There are ten test points in this problem, and each test point is worth 10%10\% of the total score. For each test point, if your answer is correct, you will get the full score for that test point; otherwise, you will get 00 points.

Note that in the testdata of this problem, there are 88 cases where nn does not exceed 180180.

Translated by ChatGPT 5