#P8408. [COCI 2009/2010 #6] GREMLINI

[COCI 2009/2010 #6] GREMLINI

Problem Description

There are nn types of gremlins. We number these nn types as 1,,n1,\dots,n.

tt years ago, an accident created nn gremlins (consider them newborn, not mature), and their types were all different.

After a type ii gremlin is born, it needs yiy_i years to mature. Once it matures, it immediately lays kik_i eggs (gremlins reproduce asexually) and then dies. Number its eggs as 1,,ki1,\dots,k_i. The jj-th egg needs hi,jh_{i,j} years to hatch, and the hatched gremlin’s type is gi,jg_{i,j}.

Ask: up to which generation is the gremlin that is currently the farthest from the ancestor, ignoring eggs that have not hatched yet. Assume the ancestor is generation 00, its children are generation 11, grandchildren are generation 22, and so on.

Input Format

The first line: n,tn,t. Then follow 3n3n lines, grouped by three lines per type.

The first line of each group: ki,yik_i,y_i. The second line of each group: gi,1,,gi,kig_{i,1},\ldots,g_{i,k_i}. The third line of each group: hi,1,,hi,kih_{i,1},\ldots,h_{i,k_i}.

Output Format

One line with one integer, representing the largest generation number among gremlins that currently exist.

1 42
1 10
1
5
2
2 42
1 10
1
5
1 5
1
5
3
3 8
4 5
1 2 3 2
1 2 1 3
1 1
3
1
2 1
1 2
2 1
4

Hint

[Sample #1 Explanation]

1010 years after the accident, the initial gremlin (generation 00) laid one egg and then died. 1515 years after the accident, the egg hatched into a new gremlin (generation 11). 2525 years after the accident, the generation 11 gremlin laid one egg and then died. 3030 years after the accident, the egg hatched into a new gremlin (generation 22). 4040 years after the accident, the generation 22 gremlin laid one egg and then died. 4242 years after the accident, this egg had still not hatched, so it is not counted.

[Constraints]

$1 \le n \le 100,1 \le t \le 10^{15},1 \le k_i, y_i, h_{i,j} \le 1000,1 \le g_{i,j} \le n$。

The score of this problem follows the original COCI settings, with a full score of 130130.

Translated by ChatGPT 5