#K94402. Maximum Orbit Depth

    ID: 38633 Type: Default 1000ms 256MiB

Maximum Orbit Depth

Maximum Orbit Depth

You are given a system of orbits representing the flow from a central planet (node 1) to its moons. Every orbit is a directed edge from one node (planet or moon) to another moon. Given two integers P and M – where P denotes the number of planets (with planet 1 as the central planet) and M denotes the number of orbits – and a list of M directed edges, your task is to determine the maximum depth of any moon reachable from the central planet. The depth is defined as the number of hops (edges) required to reach that moon from planet 1.

Note: The orbits form a directed acyclic structure where each edge goes from a planet to its moon. If there are no orbits, the depth is 0.

The formula for depth can be expressed as follows in \(\LaTeX\) format:

\(\text{maxDepth} = \max_{v \in \text{reachable from } 1} (d(1,v))\), where \(d(1,v)\) is the number of edges in the shortest path from node 1 to node v.

inputFormat

The first line contains two integers \(P\) and \(M\), representing the number of planets and the number of orbits respectively. Each of the following \(M\) lines contains two integers \(u\) and \(v\) which indicates a directed orbit from planet \(u\) to moon \(v\).

It is guaranteed that the central planet is labeled 1.

outputFormat

Output a single integer denoting the maximum depth (number of hops) from the central planet (planet 1) to any moon reachable via the provided orbits.

## sample
3 3
1 2
2 3
1 4
2

</p>