8679: Serval and Essay

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述


Serval is a new student in Japari Kindergarten.

There is an English course in the kindergarten. The teacher sets some writing tasks for students to improve their writing skills. Therefore, Serval has to complete an essay, in English.

You might know that in an essay, the author has to convince readers of several arguments by showing them evidence.

Serval have collected nnn available arguments numbered from 111 to nnn that can be written in his essay. For the iii-th argument, Serval can conclude that iii-th argument is true when the arguments numbered ai,1,ai,2,…,ai,kia_{i,1}, a_{i,2}, \dots, a_{i,k_i}ai,1,ai,2,,ai,ki are all true. Specially, the iii-th argument cannot be proven true by making conclusion when ki=0k_i = 0ki=0. It is guaranteed that ai,j≠ia_{i,j}\neq iai,j=i for all iii (1≤i≤n1\leq i\leq n1in), and ai,j≠ai,ka_{i,j}\neq a_{i,k}ai,j=ai,k when j≠kj\neq kj=k.

At the beginning of his essay, Serval will set exactly one argument from all the arguments as the argument basis, which is regarded as true. Starting with the argument basis, Serval will claim that some other arguments are true by making conclusions to complete his essay. It can be shown that for the iii-th argument with ki=0k_i = 0ki=0, it can be true if and only if it is the argument basis.

Serval wants to maximize the number of true arguments in the essay, so he needs to set the argument basis optimally. However, as a kindergarten student, he cannot even find out the number of true arguments he can obtain.

Could you help him find out the answer?

输入格式


Each test contains multiple test cases.
The first line contains an integer TTT (1≤T≤1051\leq T\leq 10^51T105) — the number of test cases.
For each test case:
The first line contains a single integer nnn (1≤n≤2×1051\leq n\leq 2\times 10^51n2×105) — the number of the available arguments.
For the iii-th line in the following nnn lines, there is an integer kik_iki (0≤ki<n0\le k_{i} < n0ki<n) followed by kik_iki integers ai,1,ai,2,…,ai,kia_{i,1},a_{i,2},\dots,a_{i,k_i}ai,1,ai,2,,ai,ki (1≤ai,j≤n,ai,j≠i1\le a_{i,j}\le n,a_{i,j}\neq i1ai,jn,ai,j=i) — the arguments required to make the conclusion for the iii-th argument. It is guaranteed that ai,j≠ia_{i,j}\neq iai,j=i for all iii (1≤i≤n1\leq i\leq n1in), and ai,j≠ai,ka_{i,j}\neq a_{i,k}ai,j=ai,k when j≠kj\neq kj=k.
It is guaranteed that the sum of nnn in all the test cases does not exceed 2×1052\times 10^52×105 and the sum of kik_iki in all the test cases does not exceed 5×1055\times 10^55×105.

输出格式


For the iii-th test case, print a line containing "" (without quotes), where iii is the number of the test case starting from 111 and xxx is the answer to the test case, which is the maximum number of true arguments when setting the argument basis optimally.

输入样例 复制

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

输出样例 复制

Case #1: 4
Case #2: 3
Case #3: 4

数据范围与提示


For the first sample, Serval can set the 111-st argument as the argument basis to obtain 444 true arguments in the essay. The following process shows how Serval makes conclusions in his essay.
⋅\cdot Set the 111-st argument as the argument basis, which is regarded as true.
⋅\cdot Conclude that 222-nd argument is true because 111-st argument is true. ⋅\cdot Conclude that 333-rd argument is true because both 111-st and 222-nd arguments are true. ⋅\cdot Conclude that 444-th argument is true because both 222-nd and 333-rd arguments are true.

分类标签