#C8817. Maximum Folder Depth

    ID: 52841 Type: Default 1000ms 256MiB

Maximum Folder Depth

Maximum Folder Depth

You are given a folder structure represented by n pairs of integers. Each pair describes a folder and its parent folder. The folder with a parent id of -1 is the root folder. Your task is to compute the maximum depth of the folder tree. The depth of the tree is defined as the number of levels from the root to the deepest folder (with the root at depth 1).

For example, consider the folder structure given by the pairs:

1 -1
2 1
3 1
4 2
5 4

The maximum depth is 4. In terms of a recurrence relation, if we denote the depth of folder i as \(d(i)\), then:

[ d(i) = \begin{cases} 1, & \text{if the folder is the root} \ 1+ d(p), & \text{if } p \text{ is its parent} \end{cases} ]

where the root is the folder whose parent's id is \(-1\).

inputFormat

The first line contains an integer n, the number of folders.

Each of the following n lines contains two space-separated integers: the folder id and its parent's id. A parent's id of -1 indicates that this folder is the root folder.

outputFormat

Output a single integer representing the maximum depth of the folder structure.

## sample
3
1 -1
2 1
3 1
2