Solution to Tree Depth from Jobdu

7 Sep

Question (in Chinese):

Question Name: Tree Depth

Question Description: compute the depth of a binary tree.

Input: the input might contain multiple test cases. Inside each test case, the first line includes one integers N (1 <= N <= 10), saying the number of nodes in the binary tree. The following N lines indicate the sons of the nodes (1-based index, and the first node is the root node). i(th) line contains two integers X and Y. And the X(th) node is the left son of i(th) node, and Y(th) the right son. X/Y is -1, if there is no such son.

Output: print the height of the tree.

The solution is:

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!