P22469 [CodeChef] LARGEFAM
普及
题目描述

A certain parallel universe has exactly N people living in it.

The i-th of these N people claims that they are the parent of exactly A_{i} of these N people.

However, some of these people might be lying — the i-th person may be either telling the truth (in which case they have exactly A_{i} children) or lying (in which case they can have any number of children).

It is known that each person has at most one parent. Further, as one would expect, it is not allowed for a person's child to also be their ancestor.

What is the maximum possible number of truth-tellers in this universe?

------ Input Format ------

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of two lines of input.
  • The first line of each test case contains a single integer N, the number of people.
  • The second line of each test case contains $N space-separated integers A_{1}, A_{2}, \ldots, A_{N}$.

------ Output Format ------

For each test case, output on a new line the maximum number of people that can be telling the truth.

------ Constraints ------

$1 ≤ T ≤ 4 \cdot 10^{4}$
$1 ≤ N ≤ 3\cdot 10^{5}$
$0 ≤ A_{i} < N$
- The sum of $N$ across all test cases won't exceed $3 \cdot 10^{5}$.

------ subtasks ------

Subtask 1 (20 points):
$1 ≤ T ≤ 5$
$1 ≤ N ≤ 20$
Subtask 2 (80 points):
No further constraints.

----- Sample Input 1 ------
4
2
1 0
2
1 1
3
2 0 1
5
2 3 1 2 3

----- Sample Output 1 ------
2
1
2
2

----- explanation 1 ------
Test case $1$: Both people can be telling the truth, with the first person being the parent of the second.

Test case $2$: If both people were telling the truth, they would be each others' parents — and that is not allowed. Hence, at most one of them can be telling the truth.

Test case $3$: The first and third people cannot be telling the truth at the same time. However, it is possible for the first and second people to be truthful — person $1$ can be the parent of person $2$ and person $3$. Hence, the answer is $2$.

Test case $4$: There are several ways to pick $2$ people to be telling the truth — for example,
- The parent of person $2$ and person $3$ is person $1$
- The parent of person $1$ and person $5$ is person $4$

in which case persons number $1$ and $4$ would be telling the truth.

However, it can be shown that it is impossible for any three of them to be simultaneously telling the truth.

输入格式

见题面

输出格式

见题面

样例输入
4 2 1 0 2 1 1 3 2 0 1 5 2 3 1 2 3
样例输出
2 1 2 2