#abc289c. C - Coverage

C - Coverage

Score : 300300 points

问题描述

设有 MM 个集合,分别记作 S1,S2,,SMS_1, S_2, \dots, S_M,包含从 11NN 的整数。
其中,集合 SiS_i 包含 CiC_i 个整数 ai,1,ai,2,,ai,Cia_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}

从这 MM 个集合中选择一个或多个集合的方式有 (2M1)(2^M-1) 种。
其中满足以下条件的组合方式有多少种?

  • 对于所有满足 1xN1 \leq x \leq N 的整数 xx,至少有一个被选中的集合包含 xx

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are MM sets, called S1,S2,,SMS_1, S_2, \dots, S_M, consisting of integers between 11 and NN.
SiS_i consists of CiC_i integers ai,1,ai,2,,ai,Cia_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}.

There are (2M1)(2^M-1) ways to choose one or more sets from the MM sets.
How many of them satisfy the following condition?

  • For all integers xx such that 1xN1 \leq x \leq N, there is at least one chosen set containing xx.

Constraints

  • 1N101 \leq N \leq 10
  • 1M101 \leq M \leq 10
  • 1CiN1 \leq C_i \leq N
  • $1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

C1C_1

a1,1a_{1,1} a1,2a_{1,2} \dots a1,C1a_{1,C_1}

C2C_2

a2,1a_{2,1} a2,2a_{2,2} \dots a2,C2a_{2,C_2}

\vdots

CMC_M

aM,1a_{M,1} aM,2a_{M,2} \dots aM,CMa_{M,C_M}

Output

Print the number of ways to choose sets that satisfy the conditions in the Problem Statement.

Sample Input 1

3 3
2
1 2
2
1 3
1
2

Sample Output 1

3

The sets given in the input are $S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace$.
The following three ways satisfy the conditions in the Problem Statement:

  • choosing S1,S2S_1, S_2;
  • choosing S1,S2,S3S_1, S_2, S_3;
  • choosing S2,S3S_2, S_3.

Sample Input 2

4 2
2
1 2
2
1 3

Sample Output 2

0

There may be no way to choose sets that satisfies the conditions in the Problem Statement.

Sample Input 3

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

Sample Output 3

18

update @ 2024/3/10 12:04:22