410699: GYM104077 L Tree

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Treetime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

You are given a tree $$$T$$$ with $$$n$$$ nodes. The tree is rooted at $$$1$$$. Define $$$\mathrm{subtree}(u)$$$ as the set of nodes in the subtree of $$$u$$$.

Call a subset of nodes $$$S$$$ good if and only if $$$S$$$ satisfies at least one of the following contidions:

  • For all $$$u, v\in S$$$ where $$$u\neq v$$$, either $$$u\in \mathrm{subtree}(v)$$$ or $$$v\in \mathrm{subtree}(u)$$$.
  • For all $$$u, v\in S$$$ where $$$u\neq v$$$, both $$$u\notin \mathrm{subtree}(v)$$$ and $$$v\notin \mathrm{subtree}(u)$$$.

You need to partition all nodes of $$$T$$$ into several good subsets. Calculate the minimum number of subsets.

Input

The first line contains a single integer $$$Q$$$ ($$$1\leq Q\leq 10 ^ 5$$$), denoting the number of test cases.

For each test case, the first line contains an integer $$$n$$$ ($$$1\leq n\leq 10 ^ 6$$$). The next line contains $$$n - 1$$$ integers $$$p_2, p_3, \ldots, p_n$$$ ($$$1\leq p_i < i$$$), indicating that there is an edge between $$$p_i$$$ and $$$i$$$ for each $$$i=2,3,\ldots,n$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases is no more than $$$10 ^ 6$$$.

Output

For each test case, output a single integer representing the answer.

ExampleInput
2
7
1 1 2 2 2 3
5
1 2 3 4
Output
3
1

加入题单

算法标签: