#K60832. Longest Path in a Planetary Tree

    ID: 31174 Type: Default 1000ms 256MiB

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:

L=maxvVd(1,v),L = \max_{v \in V} d(1,v),

where d(1,v)d(1,v) is the number of edges from Planet 1 to planet vv.

Input Format: The first line contains an integer NN representing the number of planets. For N>1N > 1, the next N1N-1 lines each contain two space-separated integers uu and vv, which denote a wormhole from planet uu to planet vv.

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 NN, the number of planets. For N>1N > 1, the following N1N-1 lines each contain two integers uu and vv, representing a directed edge (wormhole) from planet uu to planet vv.

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>