{"problem":{"name":"Martial artist","description":{"content":"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","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc226_c"},"statements":[{"statement_type":"Markdown","content":"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$.\nTakahashi 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$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 2\\times 10^5$\n*   $1 \\leq T_i \\leq 10^9$\n*   $0 \\leq K_i < i$\n*   $1 \\leq A_{i,j} < i$\n*   $\\sum_{i=1}^N K_i \\leq 2\\times 10^5$\n*   $A_{i,1}$, $A_{i,2}$, $\\ldots$, $A_{i,K_i}$ are all distinct.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$T_1$ $K_1$ $A_{1,1}$ $A_{1,2}$ $\\ldots$ $A_{1,K_1}$\n$T_2$ $K_2$ $A_{2,1}$ $A_{2,2}$ $\\ldots$ $A_{2,K_2}$\n$\\vdots$\n$T_N$ $K_N$ $A_{N,1}$ $A_{N,2}$ $\\ldots$ $A_{N,K_N}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc226_c","tags":[],"sample_group":[["3\n3 0\n5 1 1\n7 1 1","10\n\nHere is one possible plan for Takahashi.\n\n*   At time $0$, start practicing for Move $1$ to learn Move $1$ at time $3$.\n*   Then, at time $3$, start practicing for Move $3$ to learn Move $3$ at time $10$.\n\nHere, 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$."],["5\n1000000000 0\n1000000000 0\n1000000000 0\n1000000000 0\n1000000000 4 1 2 3 4","5000000000\n\nNote that the answer may not fit into a $32$\\-bit integer."]],"created_at":"2026-03-03 11:01:14"}}