Problem G: 二叉树中节点最远距离

Memory Limit:128 MB Time Limit:2.000 S
Judge Style:Text Compare Creator:
Submit:91 Solved:46

Description

给定一前序二叉树的数据,请构造根节点为 root 的二叉树,求一棵二叉树中相距最远的两个节点之间的距离。

Input

给定一棵树的前序遍历,如果子节点是空,则用0表示,并以-1结尾。

例如:

4 2 1 0 0 3 0 0 6 5 0 0 7 0 0 -1                  

Output

输出两节点的最大距离

Sample Input Copy

4 2 1 0 0 3 0 0 6 5 0 0 7 0 0 -1

Sample Output Copy

4

HINT

二叉树的深度小于35。