#P2458. [SDOI2006] 保安站岗

[SDOI2006] 保安站岗

Description

With Labor Day approaching, an underground supermarket plans to temporarily call in security guards from other units to direct and ease the flow of dense crowds and vehicles, so as to avoid chaos and congestion inside the supermarket.

All passages in the underground supermarket form a tree. Some passages can be seen from one another. The general manager requires every endpoint of every passage (i.e., every tree vertex) to be watched around the clock. The cost of assigning a guard at different passage endpoints varies.

If a guard stands at one endpoint of a passage, then besides guarding the endpoint where they stand, they can also see the other endpoint of that passage. Therefore, a single guard may be able to watch multiple endpoints (tree vertices), and it is not necessary to assign a guard to every endpoint of every passage.

Task:

Please help the supermarket manager plan the arrangement so that all passage endpoints are watched, while minimizing the total cost.

Input Format

The first line contains nn, the number of nodes in the tree.

Lines 22 through n+1n+1 each describe one passage endpoint (node), in the following order: the node label ii (0<in0 < i \le n), the cost kk of placing a guard at this node (1k100001 \le k \le 10000), the number of children of this node mm, followed by mm integers, which are the labels of this node’s mm children r1,r2,,rmr_1, r_2, \cdots, r_m.

For a tree with nn (0<n15000 < n \le 1500) nodes, node labels are between 11 and nn, and labels are not repeated.

Output Format

Output a single integer on one line: the minimum total cost.

6
1 30 3 2 3 4
2 16 2 5 6
3 5 0
4 4 0
5 11 0
6 5 0
25

Hint

Sample explanation:

Placing 33 guards at nodes 2,3,42, 3, 4 can watch all 66 nodes, and the minimum cost is 2525.

Translated by ChatGPT 5