#P10092. [ROIR 2022] 网络系统升级计划 (Day 2)
[ROIR 2022] 网络系统升级计划 (Day 2)
Background
Translated from ROIR 2022 D2T3.
A country has cities, numbered from to , and the capital is city .
The computer network of this country is built as follows: each city has a connection hub, and hubs can be connected to some other hubs via wired communication links. Between any two cities, there is exactly one communication path; in other words, the network forms a tree. For city , denote by the first city on the path from city to the capital.
The network is planned to be upgraded by replacing some existing wired links with more advanced optical communication links. Optical links can only be laid where an existing wired link is. The cost to replace the communication link connecting city and is . Due to technical limitations, any connection hub can be directly connected to at most other hubs.
Problem Description
The Ministry of Communications wants to make an upgrade plan to improve the connectivity of optical communication links. Therefore, it needs to upgrade as many communication links as possible. If multiple plans upgrade the same number of links, it wants the total upgrade cost to be as small as possible; that is, among those plans, choose the one with the minimum total cost.
Help the experts of the Ministry of Communications choose which communication links to upgrade.
Input Format
The first line contains two integers and .
The next lines describe the communication links. The -th of these lines contains two integers: and ().
Output Format
Output two integers and , representing the maximum number of communication links that can be upgraded and the minimum cost to upgrade those links.
8 2
1 0
1 0
1 0
2 0
2 0
2 0
1 0
4 0
8 3
1 5
1 2
1 4
2 6
2 7
2 2
1 6
6 27
Hint
In Sample , the network configuration before and after the upgrade is shown in the figure below. The links to be upgraded are shown in bold. The maximum number of links that can be upgraded is .

In Sample , the network configuration before and after the upgrade is shown in the figure below. The links to be upgraded are shown in bold. The upgrade cost is shown next to each edge (communication link). In the optimal solution, the total cost of the upgraded links is , and the maximum number of links that can be upgraded is .

In the original problem, there are subtasks, but Luogu does not support setting more than subtasks. The original problem has testdata points, but Luogu does not support setting more than testdata points. Therefore, this problem only keeps the last testdata points, and does not use bundled tests.
All data satisfy .
Translated by ChatGPT 5