#K35052. Deepest Reply Depth

    ID: 25445 Type: Default 1000ms 256MiB

Deepest Reply Depth

Deepest Reply Depth

Given a list of messages, each represented as a pair of integers (message ID, replied-to message ID), determine the depth of the deepest nested reply. A message with a replied-to message ID of 0 is considered a top-level post with a depth of 1. For any other message, its depth is one plus the depth of the message it replies to.

For example, consider the list of messages:

[(1, 0), (2, 1), (3, 2), (4, 1), (5, 0)]

The deepest reply depth is 3.

Your task is to compute and output the deepest reply depth based on the provided input.

inputFormat

The first line contains a single integer n, the number of messages. Each of the next n lines contains two space-separated integers a and b, where a is the message ID and b is the replied-to message ID (0 indicates a top-level post).

outputFormat

Output a single integer representing the depth of the deepest nested reply.## sample

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

</p>