can some one solve this?

You live in a kingdom which contains N villages and M=(N-1) roads,such that there exists exactly one path between any two villages.You have enough energy to walk exact K hours.You can choose the starting village arbitarily,In one hour,you can go from current village to adjacent village.
How man maximum number of villages can you visit?
image

The below kingdom represents a tree.It can be rooted at any village.
You are given the parent array having M=(N-1) elements.

function parameters:
parent (integer array): parent[i] denotes parent of node i+1
K(integer): max number of hours you can walk

sample test cases:

Input:M=6(number of roads)
parent=[0,1,1,3,3,3,6]
k=6

Comments (3)