102262: [AtCoder]ABC226 C - Martial artist

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

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

Takahashi has not learned any move at time $0$. 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 $N$.

Constraints

  • $1 \leq N \leq 2\times 10^5$
  • $1 \leq T_i \leq 10^9$
  • $0 \leq K_i < i$
  • $1 \leq A_{i,j} < i$
  • $\sum_{i=1}^N K_i \leq 2\times 10^5$
  • $A_{i,1}$, $A_{i,2}$, $\ldots$, $A_{i,K_i}$ are all distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$T_1$ $K_1$ $A_{1,1}$ $A_{1,2}$ $\ldots$ $A_{1,K_1}$
$T_2$ $K_2$ $A_{2,1}$ $A_{2,2}$ $\ldots$ $A_{2,K_2}$
$\vdots$
$T_N$ $K_N$ $A_{N,1}$ $A_{N,2}$ $\ldots$ $A_{N,K_N}$

Output

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


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 $0$, start practicing for Move $1$ to learn Move $1$ at time $3$.
  • Then, at time $3$, start practicing for Move $3$ to learn Move $3$ at time $10$.

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


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 $32$-bit integer.

Input

Output

得分:300分 部分 问题描述 Takahashi是一名武术家。一个武术家可以学习$N$种招式,分别称为招式1、2、$\ldots$、$N$。对于每个$1 \leq i \leq N$,学习招式$i$需要$T_i$分钟的练习时间。此外,在该练习开始时,必须已经学会了所有的招式$A_{i,1}$、$A_{i,2}$、$\ldots$、$A_{i,K_i}$。在这里,对于每个$1 \leq j \leq K_i$,保证$A_{i,j} < i$。 在时间0时,Takahashi没有学习任何招式。他不能同时练习超过一招,也不能中途停止已经开始的练习。求Takahashi学习招式$N$所需的最短时间(以分钟为单位)。 部分 约束 * $1 \leq N \leq 2\times 10^5$ * $1 \leq T_i \leq 10^9$ * $0 \leq K_i < i$ * $1 \leq A_{i,j} < i$ * $\sum_{i=1}^N K_i \leq 2\times 10^5$ * $A_{i,1}$、$A_{i,2}$、$\ldots$、$A_{i,K_i}$都是不同的。 * 输入中的所有值都是整数。 部分 输入 输入通过标准输入给出以下格式: ``` $N$ $T_1$ $K_1$ $A_{1,1}$ $A_{1,2}$ $\ldots$ $A_{1,K_1}$ $T_2$ $K_2$ $A_{2,1}$ $A_{2,2}$ $\ldots$ $A_{2,K_2}$ $\vdots$ $T_N$ $K_N$ $A_{N,1}$ $A_{N,2}$ $\ldots$ $A_{N,K_N}$ ``` 部分 输出 打印出Takahashi学习招式$N$所需的最短时间(以分钟为单位)。 部分 样例输入1 ``` 3 3 0 5 1 1 7 1 1 ``` 部分 样例输出1 ``` 10 ``` 这里给出了Takahashi的一种可能的计划。 * 在时间0时,开始练习招式1,以便在时间3时学会招式1。 * 然后,在时间3时,开始练习招式3,以便在时间10时学会招式3。 在这里,Takahashi花了$3+7=10$分钟学习招式3,这是最快的可能。注意,他不需要学习招式2来学习招式3。 部分 样例输入2 ``` 5 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 4 1 2 3 4 ``` 部分 样例输出2 ``` 5000000000 ``` 注意,答案可能不适合32位整数。

加入题单

上一题 下一题 算法标签: