#P9369. [ICPC2022 Xi'an R] Tree
[ICPC2022 Xi'an R] Tree
题目描述
You are given a tree with nodes. The tree is rooted at . Define as the set of nodes in the subtree of .
Call a subset of nodes good if and only if satisfies at least one of the following contidions:
- For all where , either or .
- For all where , both and .
You need to partition all nodes of into several good subsets. Calculate the minimum number of subsets.
输入格式
The first line contains a single integer (), denoting the number of test cases.
For each test case, the first line contains an integer (). The next line contains integers (), indicating that there is an edge between and for each .
It is guaranteed that the sum of over all test cases is no more than .
输出格式
For each test case, output a single integer representing the answer.
题目大意
题目描述
给定大小为 的有根树 ,根节点为 。定义 表示结点 的子树。
称集合 是好的,当且仅当 至少满足下列条件之一:
- 对于 且 , 或 。
- 对于 且 , 且 。
将 划分为若干好的集合,求集合数量的最小值。
共有 组数据。
,,每个点的父亲编号 。
输入格式
第一行一个整数 。
对于每组测试数据,第一行一个整数 ,第二行 个由空格隔开的整数 ,表示每个点的父亲编号。
输出格式
对于每组测试数据,输出一行一个整数表示答案。
2
7
1 1 2 2 2 3
5
1 2 3 4
3
1
提示
Source: The 2022 ICPC Asia Xi'an Regional Contest Problem L.
Author: Alex_Wei.