P6479 [CRCI2006-2007] BARD

Description

There is a small village with $n$ people. Number these $n$ people from $1$ to $n$. Person $1$ is the bard. Every night, some villagers gather around the campfire and sing. If the bard comes on a certain night, the bard will compose a new song that nobody has heard before and teach it to everyone there. On that night, **no other songs will be sung**. If the bard does not come on a certain night, then the participants will sing **all songs** that **at least one of them** knows, and teach these songs to those who came but do not know them. You are given the IDs of the villagers who participate in singing on each of the $m$ nights. At the beginning, the villagers do not know any songs, and the bard has not written any songs. Output how many villagers will finally know all songs written by the bard.

Input Format

The first line contains an integer, the number of villagers $n$. The second line contains an integer, the number of nights $m$. Lines $3$ to $(m + 2)$ describe each night. Line $(i + 2)$ describes night $i$: The line first contains an integer $k_i$, meaning $k_i$ villagers came that night, followed by $k_i$ distinct integers $a_{i, j}$, which are the IDs of the villagers who came.

Output Format

Output several lines, one integer per line, listing in **ascending order** the ID of each villager who knows all songs.

Explanation/Hint

#### Constraints For all testdata, it is guaranteed that: - $1 \leq n \leq 100$, $1 \leq m \leq 50$. - $2 \leq k_i \leq n$, $1 \leq a_{i, j} \leq n$. $1$ appears in $a_{i, j}$ at least once. #### Notes **Translated from [COCI2006-2007](https://hsin.hr/coci/archive/2006_2007/) [Regional Competition](https://hsin.hr/coci/archive/2006_2007/regional_tasks.pdf) *T1 BARD***. Translation by @[一扶苏一](https://www.luogu.com.cn/user/65363)。 Translated by ChatGPT 5