QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#11576. 九头蛇

统计

小 Bytie 生日时收到了一份礼物,里面包含一款名为《骑士 Byteasar 的奇妙冒险》的电脑游戏。这款游戏的目标是带领骑士通过重重挑战,击败恶棍和邪恶女巫,并拯救遇险的少女。

小 Bytie 已经完成了游戏中几乎所有的关卡。现在他卡在了最后一关,Byteasar 需要与一条巨蛇——Bytean Hydra 进行战斗。

Byteasar 将使用他的剑与怪物战斗。游戏中提供两种剑术:Byteasar 可以选择砍掉蛇头,或者直接屠杀蛇头(显然,后者需要消耗更多的体力)。砍掉蛇头虽然简单,但会导致蛇颈处长出新的头。只有当九头蛇不再有头,且其颈部无法再长出新头时,它才会被击败。

Bytean Hydra 可能拥有编号为 $1$ 到 $n$ 的多种类型的头。起初,蛇有一个 $1$ 类型的头。对于 $1 \le i \le n$,类型为 $i$ 的头具有以下特征:砍掉一个该类型的头所需的剑术次数 $u_i$,屠杀一个该类型的头所需的剑术次数 $z_i$,以及砍掉该类型的头后长出的新头的类型列表 $g_{i,1}, \dots, g_{i,r_i}$。

请帮助 Bytie 计算击败 Hydra 所需的最少剑术次数。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 200\,000$),表示 Hydra 的头类型数量。 接下来的 $n$ 行描述了各类型的头。第 $i$ 行描述了类型为 $i$ 的头。该行以三个整数 $u_i, z_i, r_i$ ($1 \le u_i, z_i \le 10^9, 1 \le r_i \le n$) 开头,随后是 $r_i$ 个整数 $g_{i,1}, \dots, g_{i,r_i}$ ($1 \le g_{i,j} \le n$)。所有 $r_i$ 的总和不超过 $1\,000\,000$。

输出格式

输出一行,包含一个整数:完成游戏所需的最少剑术次数。

样例

输入 1

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

输出 1

26

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.