#P8408. [COCI 2009/2010 #6] GREMLINI
[COCI 2009/2010 #6] GREMLINI
Problem Description
There are types of gremlins. We number these types as .
years ago, an accident created gremlins (consider them newborn, not mature), and their types were all different.
After a type gremlin is born, it needs years to mature. Once it matures, it immediately lays eggs (gremlins reproduce asexually) and then dies. Number its eggs as . The -th egg needs years to hatch, and the hatched gremlin’s type is .
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 , its children are generation , grandchildren are generation , and so on.
Input Format
The first line: . Then follow lines, grouped by three lines per type.
The first line of each group: . The second line of each group: . The third line of each group: .
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]
years after the accident, the initial gremlin (generation ) laid one egg and then died. years after the accident, the egg hatched into a new gremlin (generation ). years after the accident, the generation gremlin laid one egg and then died. years after the accident, the egg hatched into a new gremlin (generation ). years after the accident, the generation gremlin laid one egg and then died. 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 .
Translated by ChatGPT 5