CF1914F.Programming Competition

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

BerSoft is the biggest IT corporation in Berland. There are nn employees at BerSoft company, numbered from 11 to nn .

The first employee is the head of the company, and he does not have any superiors. Every other employee ii has exactly one direct superior pip_i .

Employee xx is considered to be a superior (direct or indirect) of employee yy if one of the following conditions holds:

  • employee xx is the direct superior of employee yy ;
  • employee xx is a superior of the direct superior of employee yy .

The structure of BerSoft is organized in such a way that the head of the company is superior of every employee.

A programming competition is going to be held soon. Two-person teams should be created for this purpose. However, if one employee in a team is the superior of another, they are uncomfortable together. So, teams of two people should be created so that no one is the superior of the other. Note that no employee can participate in more than one team.

Your task is to calculate the maximum possible number of teams according to the aforementioned rules.

输入格式

The first line contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains a single integer nn ( 2n21052 \le n \le 2 \cdot 10^5 ) — the number of employees.

The second line contains n1n-1 integers p2,p3,,pnp_2, p_3, \dots, p_n ( 1pin1 \le p_i \le n ), where pip_i is the index of the direct superior of the ii -th employee.

The sum of nn over all test cases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print a single integer — the maximum possible number of teams according to the aforementioned rules.

输入输出样例

  • 输入#1

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

    输出#1

    1
    0
    1
    3
    3
    3

说明/提示

In the first test case, team (3,4)(3, 4) can be created.

In the second test case, no team can be created, because there are only 22 employees and one is the superior of another.

In the third test case, team (2,3)(2, 3) can be created.

In the fourth test case, teams (2,4)(2, 4) , (3,5)(3, 5) and (6,7)(6, 7) can be created.

In the fifth test case, teams (2,3)(2, 3) , (6,4)(6, 4) and (5,7)(5, 7) can be created.

首页