#K51597. Compute Tree Depth
Compute Tree Depth
Compute Tree Depth
You are given a rooted tree with n nodes. Each node is described by a line containing its NodeID, the Number of Children, and the list of children IDs (if any). The tree is rooted at node 1
.
Your task is to compute the depth (height) of the tree starting from the root node. The depth is defined as the maximum number of edges in any path from the root to a leaf. If the tree contains only one node, then its depth is 0
.
Note: The input will be provided via standard input and the output must be printed to standard output.
Example:
Input: 7 1 3 2 3 4 2 2 5 6 3 0 4 0 5 1 7 6 0 7 0</p>Output: 3
inputFormat
The first line contains an integer n representing the number of nodes in the tree.
This is followed by n lines, where each line contains a node description in the format:
NodeID NumberOfChildren ChildID1 ChildID2 ... ChildIDk
For nodes with no children, the line will only contain the NodeID and 0.
outputFormat
Print a single integer representing the depth of the tree (the maximum number of edges from the root node to any leaf node).
## sample7
1 3 2 3 4
2 2 5 6
3 0
4 0
5 1 7
6 0
7 0
3