There is a rooted tree with nnn vertices and the root vertex is 111. In each vertex, there is a monster. The hit points of the monster in the iii-th vertex is hpihp_ihpi. Kotori would like to kill all the monsters. The monster in the iii-th vertex could be killed if the monster in the direct parent of the iii-th vertex has been killed. The power needed to kill the iii-th monster is the sum of hpihp_ihpi and the hit points of all other living monsters who lives in a vertex jjj whose direct parent is iii. Formally, the power equals to hpi+∑the monster in vertex j is aliveand i is the direct parent of jhpj hp_i + sumlimits_{begin{array}{c}text{the monster in vertex } j text{ is alive} \ text{and } i text{ is the direct parent of } j end{array}} hp_j hpi+the monster in vertex j is aliveand i is the direct parent of j∑hpj In addition, Kotori can use some magic spells. If she uses one magic spell, she can kill any monster using 000 power without any restriction. That is, she can choose a monster even if the monster in the direct parent is alive. For each m=0,1,2,⋯ ,nm=0,1,2,cdots,nm=0,1,2,⋯,n, Kotori would like to know, respectively, the minimum total power needed to kill all the monsters if she can use mmm magic spells.
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。HBC216013小杰的签到题,排序,枚举MonsterHunter题解
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。