#P7600. [APIO2021] 封闭道路
[APIO2021] 封闭道路
Description
In Si Shui City, there are intersections (numbered from to ). These intersections are connected by two-way roads (numbered from to ), so that between any pair of intersections there is a unique path using these roads. Road () connects intersections and .
To raise awareness about environmental protection, the mayor of Si Shui City, Pak Dengklek, plans to hold a Car-Free Day. To promote this event, Pak Dengklek will organize road closures. Pak Dengklek will first choose a non-negative integer , and then close some roads so that each intersection is directly connected to at most roads that remain open. The cost to close road is .
Please help Pak Dengklek compute, for every possible non-negative integer (), the minimum total cost to close roads.
You need to implement the following function:
int64[] minimum_closure_costs(int N, int[] U, int[] V, int[] W)
-
: the number of intersections in Si Shui City.
-
and : arrays of size , where intersection and intersection are directly connected by road .
-
: an array of size , where the cost to close road is .
-
The function must return an array of size . For each (), element is the minimum total cost such that each intersection is directly connected to at most open roads.
This function will be called exactly once.
Input Format
The sample grader reads the input data in the following format:
- Line :
- Line ():
Output Format
The sample grader outputs only one line containing an array, representing the return value of minimum_closure_costs.
5
0 1 1
0 2 4
0 3 3
2 4 2
10 5 1 0 0
4
0 1 5
2 0 10
0 3 5
20 10 5 0
Hint
Examples
Example
Consider the following call:
minimum_closure_costs(5, [0, 0, 0, 2], [1, 2, 3, 4], [1, 4, 3, 2])
In this example, there are intersections and roads, connecting intersections , and . The costs to close them are , and , respectively.

To achieve the minimum total cost:
- If Pak Dengklek chooses , then all roads must be closed, and the total cost is .
- If Pak Dengklek chooses , then roads and must be closed, and the total cost is .
- If Pak Dengklek chooses , then road must be closed, and the total cost is .
- If Pak Dengklek chooses or , then no roads need to be closed.
Therefore, minimum_closure_costs should return the array .
Example
Consider the following call:
minimum_closure_costs(4, [0, 2, 0], [1, 0, 3], [5, 10, 5])
In this example, there are intersections and roads, connecting intersections , and . The costs to close them are , and , respectively.

To achieve the minimum total cost:
- If Pak Dengklek chooses , then all roads must be closed, and the total cost is .
- If Pak Dengklek chooses , then roads and must be closed, and the total cost is .
- If Pak Dengklek chooses , then either road or road must be closed, and the total cost is .
- If Pak Dengklek chooses , then no roads need to be closed.
Therefore, minimum_closure_costs should return the array .
Constraints
- Any pair of intersections can reach each other via the roads.
- .
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号