#P2515. [HAOI2010] 软件安装
[HAOI2010] 软件安装
Description
We have software packages. For a software , it occupies units of disk space, and its value is . We want to choose some software to install on a computer with disk capacity , so that the total value of the installed software is as large as possible (i.e., the sum of is maximized).
However, there is a problem: there are dependency relationships between software. Software can work properly only if software (including software ’s direct or indirect dependencies) is installed (software depends on software ). Fortunately, a software depends on at most one other software. If a software cannot work properly, then its contribution is .
We already know the dependencies between software: software depends on . Please design a plan to install software so that the total value is as large as possible. Each software can be installed at most once. If a software has no dependency, then ; in this case, as long as this software is installed, it will work properly.
Input Format
Line 1:
Line 2:
Line 3:
Line 4: $D_1, D_2, ..., D_i, ..., D_n (0\leq D_i\leq N, D_i≠i)$
Output Format
An integer representing the maximum total value.
3 10
5 5 6
2 3 4
0 1 1
5
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号