#P4042. [AHOI2014/JSOI2014] 骑士游戏

    ID: 2991 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论2014各省省选江苏安徽最短路

[AHOI2014/JSOI2014] 骑士游戏

Description

In this game, JYY has two attack types: a normal attack and a spell attack. Both consume some of JYY’s stamina. Using a normal attack on a monster does not completely kill it; the monster’s corpse can transform into some new monsters. Note that after several normal attacks, a monster may turn into one or more monsters of the same type again. A spell attack, however, can permanently kill a monster. Of course, in general, compared with a normal attack, a spell attack consumes more stamina (but due to a game system bug, this is not guaranteed).

There are NN different kinds of monsters in the game world, numbered from 11 to NN. Now a monster of type 11 has invaded the village. JYY wants to know the minimum stamina needed to kill all monsters in the village.

Input Format

The first line contains an integer NN.

Then NN lines follow, each describing one monster type.

The ii-th line contains several integers. The first three integers are SiS_i, KiK_i, and RiR_i, meaning: for monster type ii, a normal attack costs SiS_i stamina, a spell attack costs KiK_i stamina, and after monster ii dies (by a normal attack), it spawns RiR_i new monsters. After these three integers, there are exactly RiR_i more integers, each giving the type number of one newly spawned monster. The same type number may appear multiple times.

Output Format

Output one integer on a single line: the minimum stamina required.

4
4 27 3 2 3 2
3 5 1 2
1 13 2 4 2
5 6 1 2
26

Hint

First use a normal attack costing 44 stamina, and the spawned monster types are 22, 22, and 33. Spend 1010 stamina using spell attacks to kill the two monsters of type 22. For the remaining type 33 monster, use a normal attack costing 11 stamina. Now the monsters in the village are of types 22 and 44. Finally, spend 1111 stamina using spell attacks to permanently kill these two monsters. The total stamina spent is 4+5+5+1+5+6=264 + 5 + 5 + 1 + 5 + 6 = 26.

Constraints: For all testdata, 2N2×1052 \le N \le 2 \times 10^5, 1Ri,Ri1061 \le R_i, \sum R_i \le 10^6, 1Ki,Si5×10141 \le K_i, S_i \le 5 \times 10^{14}.

Translated by ChatGPT 5