P29404 [洛谷] [CRCI2006-2007] BARD
普及
题目描述

Problem Description

In a small village, there are $n$ people, numbered from $1$ to $n$, where person number $1$ is the poet.

Every evening, some villagers gather around a bonfire to sing songs.

If the poet attends a particular evening, he composes a new song that no one has heard before and teaches it to everyone present. On this evening, no other songs are sung.

If the poet does not attend a particular evening, the attendees sing all songs that at least one person present knows, and they teach these songs to those who are present but do not know them.

Given the number of villagers $n$ and the details of $m$ evenings where villagers participate in singing, with villagers initially knowing nothing and the poet having written no songs, output the number of villagers who know all the songs written by the poet.

Input Format

The first line contains an integer, representing the number of villagers $n$.

The second line contains an integer, representing the number of evenings $m$.

From the third to the $(m + 2)$th line, each line describes an evening. The $(i + 2)$th line describes the $i$th evening:
- The line starts with an integer $k_i$, indicating the number of villagers present that evening, followed by $k_i$ distinct integers $a_{i, j}$, each representing the number of a present villager.

Output Format

Output several lines, each containing an integer, listing in ascending order the numbers of villagers who know all the songs written by the poet.

Sample Input and Output

Sample Input #1

4
3
2 1 2
3 2 3 4
3 4 2 1

Sample Output #1

1
2
4

Sample Input #2

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

Sample Output #2

1
2
6
8

Sample Input #3

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

Sample Output #3

1

Notes

Data Constraints

For all test cases, the following constraints apply:
- $1 \leq n \leq 100$, $1 \leq m \leq 50$.
- $2 \leq k_i \leq n$, $1 \leq a_{i, j} \leq n$. The number $1$ appears at least once in $a_{i, j}$.

Translation

This problem is translated from the COCI2006-2007 Regional Competition T1 BARD, translated by @一扶苏一.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

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