#abc226c. C - Martial artist

C - Martial artist

Score : 300300 points

问题描述

Takahashi 是一名武术家。武术家中可以学习 NN 种招式,分别称为第 1122\ldots、第 NN 招。对于每种 1iN1 \leq i \leq N 的招式,学习第 ii 招需要花费 TiT_i 分钟的练习时间。另外,在开始练习这一招式时,必须已经学会招式 Ai,1A_{i,1}Ai,2A_{i,2}\ldotsAi,KiA_{i,K_i}。这里保证对于每个 1jKi1 \leq j \leq K_i,都有 Ai,j<iA_{i,j} < i

在时间 00 时,Takahashi 还未学会任何招式。他不能同时练习超过一种招式,也不能在已经开始练习后中途停止。请找出 Takahashi 学会第 NN 招所需的最短分钟数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi is a martial artist. There are NN moves that a martial artist can learn, called Move 11, 22, \ldots, NN. For each 1iN1 \leq i \leq N, it takes TiT_i minutes of practice to learn Move ii. Additionally, at the beginning of that practice, all of the Moves Ai,1A_{i,1}, Ai,2A_{i,2}, \ldots, Ai,KiA_{i,K_i} must be already learned. Here, it is guaranteed that Ai,j<iA_{i,j} < i for each 1jKi1 \leq j \leq K_i.

Takahashi has not learned any move at time 00. He cannot practice for more than one move simultaneously, nor can he stop a practice he has already started. Find the minimum number of minutes needed for Takahashi to learn Move NN.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1Ti1091 \leq T_i \leq 10^9
  • 0Ki<i0 \leq K_i < i
  • 1Ai,j<i1 \leq A_{i,j} < i
  • i=1NKi2×105\sum_{i=1}^N K_i \leq 2\times 10^5
  • Ai,1A_{i,1}, Ai,2A_{i,2}, \ldots, Ai,KiA_{i,K_i} are all distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

T1T_1 K1K_1 A1,1A_{1,1} A1,2A_{1,2} \ldots A1,K1A_{1,K_1}

T2T_2 K2K_2 A2,1A_{2,1} A2,2A_{2,2} \ldots A2,K2A_{2,K_2}

\vdots

TNT_N KNK_N AN,1A_{N,1} AN,2A_{N,2} \ldots AN,KNA_{N,K_N}

Output

Print the minimum number of minutes needed for Takahashi to learn Move NN.

Sample Input 1

3
3 0
5 1 1
7 1 1

Sample Output 1

10

Here is one possible plan for Takahashi.

  • At time 00, start practicing for Move 11 to learn Move 11 at time 33.
  • Then, at time 33, start practicing for Move 33 to learn Move 33 at time 1010.

Here, Takahashi spends 3+7=103+7=10 minutes to learn Move 33, which is the fastest possible. Note that he does not need to learn Move 22 to learn Move 33.

Sample Input 2

5
1000000000 0
1000000000 0
1000000000 0
1000000000 0
1000000000 4 1 2 3 4

Sample Output 2

5000000000

Note that the answer may not fit into a 3232-bit integer.

update @ 2024/3/10 09:55:05