Farmer John's cows are living on N (2 <= N <= 200,000) different pastures conveniently numbered 1..N. Exactly N-1 bidirectional cow paths (of unit length) connect these pastures in various ways, and each pasture is reachable from any other cow pasture by traversing one or more of these paths (thus, the pastures and paths form a graph called a tree).
The input for a particular set of pastures will specify the parent node

(0 <=

<= N) for each pasture. The root node will specify parent

== 0, which means it has no parent.
The cows have organized K (1 <= K <= N/2) different political parties conveniently numbered 1..K. Each cow identifies with a single
political party; cow i identifies with political party

(1 <=

<= K). Each political party includes at least two cows.
The political parties are feuding and would like to know how much 'range' each party covers. The range of a party is the largest distance between any two cows within that party (over cow paths).
Help the cows determine party ranges.