#C4358. Longest Root-to-Leaf Path in a Tree
Longest Root-to-Leaf Path in a Tree
Longest Root-to-Leaf Path in a Tree
You are given a tree with n nodes, where the root node is always 1. The tree is described by a set of edges that connect a parent to its child. Your task is to determine the length of the longest path from the root node to any leaf node. The length of a path is defined as the number of edges in the path.
Formally, if we denote a path from the root to a leaf as \(1 \rightarrow v_1 \rightarrow v_2 \rightarrow \dots \rightarrow v_k\), then the length of the path is \(k\). You are required to output the maximum \(k\) over all such paths.
inputFormat
The first line of input contains a single integer \(n\) (the number of nodes in the tree). Each of the following \(n-1\) lines contains two space-separated integers \(u\) and \(v\), indicating there is an edge connecting node \(u\) and node \(v\).
outputFormat
Output a single integer representing the length of the longest path from the root (node 1) to any leaf node.
## sample5
1 2
1 3
2 4
2 5
2