#P9369. [ICPC 2022 Xi'an R] Tree
[ICPC 2022 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.