QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#20236. All Closed

Statistics

Sulfox the fennec fox gives you $n$ sets $S_1,S_2,\ldots,S_n$, each containing distinct integers between $0$ and $2^m-1$.

You may perform the following operation any number (possibly zero) of times: choose an integer $x$ with $0\le x< 2^m$, and for every $i=1,2,\ldots,n$, insert $x$ into $S_i$ if it is not already present.

A set $S$ is called XOR-closed if, for every $x,y\in S$, we have $x\oplus y\in S$, where $\oplus$ denotes the bitwise exclusive-OR operation.

Find the minimum number of operations required to make all $S_i$ XOR-closed, and construct any sequence of operations achieving this minimum.

Input

The first line contains two integers $n$ ($1\le n\le 2 \times 10^5$) and $m$ ($1\le m\le 20$).

The $i$-th of the next $n$ lines contains an integer $c_i$ ($c_i \ge 1$), followed by $c_i$ distinct integers $a_{i,1},a_{i,2},\ldots,a_{i,c_i}$ ($0\le a_{i,j}< 2^m$), representing the elements of $S_i$.

It is guaranteed that the sum of $c_i$ does not exceed $10^6$.

Output

On the first line, print the minimum number of operations $k$.

On the second line, print $k$ integers $x_1,x_2,\ldots,x_k$, where $x_i$ denotes the integer chosen in the $i$-th operation.

If there are multiple optimal solutions, output any of them.

Examples

Input 1

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

Output 1

3
0 7 6

Input 2

1 4
4 11 5 14 0

Output 2

0

Note

For the first example, after performing the shown operations, $S_1$ and $S_2$ become $\{0,1,6,7\}$, while $S_3$ becomes $\{0,1,2,3,4,5,6,7\}$. It can be proved that it is impossible to make all sets XOR-closed using less than $3$ operations.

For the second example, the only set is already XOR-closed, so no operation is needed.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2777EditorialOpen另一种做法 By ChatGPTAnonymous2026-09-17 23:27:10View
#2680EditorialOpen题解Sulfox2026-09-15 01:45:06View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.