Investigation

Given a tree and a thief hidden at one node, find the minimum worst-case number of queries to locate him in an optimal search strategy.

Hard8TreeDynamic programmingGreedyNo attempts yetTime limit2sMemory limit1024 MB

Problem

A robbery happened in a city of Bytelandia. The thief got away and hid somewhere in the city. You are the investigator on the case, and your goal is to find the thief and arrest him.

The city has NN houses and N1N-1 roads. Each road joins two houses, and between any two houses there is exactly one path, so the city forms a tree. The thief hides in one of the houses.

To narrow down his location you pick a house hh and search it. If the thief was hiding there, you arrest him on the spot. Otherwise you question the inhabitants of that house and they give you the following information. Picture the city as a tree rooted at house hh, and let c1,c2,,cmc_1, c_2, \dots, c_m be the children of hh. Then for some ii (1im1 \le i \le m) the thief is hiding in one of the houses of the subtree rooted at cic_i.

You keep searching houses until you find and arrest the thief. Assume the thief stays in the house he first chose for the whole investigation. The final search, the one that catches him, also counts toward the number of searched houses.

The order of the searches matters. Even a search that misses returns the information above, which sharply cuts down the set of houses where the thief can still be. So you need a strategy that makes the number of searched houses in the worst case as small as possible.

You are given the description of the city. Compute the number of houses you have to search in the worst case when you follow an optimal strategy.

Input

The first line contains the number of houses in the city, NN. Houses are numbered from 00 to N1N-1.

The second line contains N1N-1 space separated integers v1 v2  vN1v_1\ v_2\ \dots\ v_{N-1}. Integer viv_i (1iN11 \le i \le N-1) means that a road joins the house numbered viv_i and the house numbered ii, and vi<iv_i < i holds.

The limit is 2N1052 \le N \le 10^5.

Output

Print one integer, the number of houses you have to search in the worst case when you follow an optimal strategy.