#C8362. Compute Company Hierarchy Depth

    ID: 52336 Type: Default 1000ms 256MiB

Compute Company Hierarchy Depth

Compute Company Hierarchy Depth

You are given N employees numbered from 0 to N-1, where employee 0 is the head of the company.

There are R reporting relationships. Each relationship is given as a pair of integers u v, which means that employee u reports directly to employee v.

The hierarchy depth is defined as the maximum number of levels in the company, with the head at level 1. In other words, if we denote the level of an employee by \( \ell(v) \), the required answer is

[ \text{depth} = \max_{v \in {0,1,\ldots,N-1}} \ell(v) ]

Your task is to compute and output the hierarchy depth.

inputFormat

The input is read from standard input (stdin) in the following format:

N
R
u1 v1
u2 v2
... 
uR vR

Where:

  • N is the number of employees.
  • R is the number of direct reporting relationships.
  • Each of the next R lines contains two integers u v indicating that employee u reports directly to employee v.

outputFormat

Output a single integer representing the depth of the company hierarchy. The output should be written to standard output (stdout).

## sample
1
0
1

</p>