#K60832. Longest Path in a Planetary Tree
Longest Path in a Planetary Tree
Longest Path in a Planetary Tree
You are given a hierarchy of planets forming a tree structure. Each directed edge represents a wormhole from one planet to another. Planet 1 is the root of the tree, and you need to find the maximum number of wormholes that can be traversed from Planet 1 to any other planet.
The problem can be formulated as follows:
where is the number of edges from Planet 1 to planet .
Input Format: The first line contains an integer representing the number of planets. For , the next lines each contain two space-separated integers and , which denote a wormhole from planet to planet .
Output Format: Output a single integer indicating the length of the longest path starting from Planet 1.
inputFormat
The input is provided via standard input.
The first line contains an integer , the number of planets. For , the following lines each contain two integers and , representing a directed edge (wormhole) from planet to planet .
outputFormat
Output a single integer to standard output, which is the length of the longest path from planet 1 in the given tree structure.## sample
1
0
</p>