{"problem":{"name":"[ICPC 2022 Xi'an R] Tree","description":{"content":"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$ satisfie","description_type":"Markdown"},"platform":"Luogu","limit":{"time_limit":2000,"memory_limit":524288},"difficulty":{"LuoguStyle":"P4"},"is_remote":true,"is_sync":true,"sync_url":null,"sign":"LGP9369"},"statements":[{"statement_type":"Markdown","content":"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$.\n\nCall a subset of nodes $S$ good if and only if $S$ satisfies at least one of the following contidions:\n\n- For all $u, v\\in S$ where $u\\neq v$, either $u\\in \\mathrm{subtree}(v)$ or $v\\in \\mathrm{subtree}(u)$.\n- For all $u, v\\in S$ where $u\\neq v$, both $u\\notin \\mathrm{subtree}(v)$ and $v\\notin \\mathrm{subtree}(u)$.\n\nYou need to partition all nodes of $T$ into several good subsets. Calculate the minimum number of subsets.\n\n## Input\n\nThe first line contains a single integer $Q$ ($1\\leq Q\\leq 10 ^ 5$), denoting the number of test cases.\n\nFor 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$.\n\nIt is guaranteed that the sum of $n$ over all test cases is no more than $10 ^ 6$.\n\n## Output\n\nFor each test case, output a single integer representing the answer.\n\n[samples]\n\n## Note\n\n**Source**: The 2022 ICPC Asia Xi'an Regional Contest Problem L.\n\n**Author**: Alex_Wei.","is_translate":false,"language":"English"}],"meta":{"iden":"LGP9369","tags":["2022","O2优化","ICPC","西安"],"sample_group":[["2\n7\n1 1 2 2 2 3\n5\n1 2 3 4\n","3\n1\n"]],"created_at":"2026-03-03 11:09:25"}}