A-3 The Farthest Distance in the World
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Rabindranath Tagore wrote in "The Farthest Distance in the World":
The farthest distance in the world
is not the distance between two trees
but the branches cannot depend on each other in wind even they grow from the same root
Given a tree, the distance between a pair of nodes is the minimum number of edges one must pass when moving from one node to the other. Your job is to calculate the farthest distance between all pairs of nodes in a tree.
输入格式
Each input file contains one test case. For each case, the first line gives a positive integer ( ) which is the number of nodes in the tree. Hence the nodes are numbered from 1 to . Then numbers are given in the next line. The -th number is the index of the parent node of the -th node, and the parent of the only root node is .
输出格式
Print in a line the farthest distance between all pairs of nodes in the tree.
题目示例数据
13
8 4 -1 3 3 4 4 6 7 7 10 9 11
7