Given is a tree on n nodes.
The nodes are numbered 0 through n-1.
You are given the description of the tree as a int parent with n-1 elements.
For each valid i, there is an edge between vertices (i+1) and parent[i].
A person is currently standing in node 0.
In a single step, the person can move from its current node to any adjacent node.
You are given an int L.
The person is allowed to make at most L steps.
Return the maximum number of nodes the person can visit during the walk.
Node 0 (where the walk starts) and the node where the walk ends count as visited.
Each visited node is only counted once, even if it is visited multiple times.
|Method signature:||int maxNodesVisited(int parent, int L)|
|(be sure your method is public)|
|-||parent will contain between 0 and 49 elements, inclusive.|
|-||For each i, parent[i] will be between 0 and i, inclusive.|
|-||L will be between 1 and 100, inclusive.|
|The tree consists of edges 1-0 and 2-0.
Our person will start in node 0 and can make at most L=2 steps.
In two steps, the best we can do is visit one of the nodes 1 and 2.|
|This is the same tree, only now we have L=3.
In three steps the person can visit all three nodes: for example, by going from node 0 to node 1, back to node 0, and finally to node 2.
Note that even though the person visited node 0 twice, we only count it once.|
|As the tree is very small and L large, the person can easily visit all nodes.|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.