logo AlgoBeat OnlineJudge
登录 注册

#208815. [ICPC 2022 Xi'an R] Tree

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

样例

样例输入 1

2
7
1 1 2 2 2 3
5
1 2 3 4

样例输出 1

3
1

数据范围与提示

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem L.

Author: Alex_Wei.