#P6479. [CRCI2006-2007] BARD

[CRCI2006-2007] BARD

Problem Description

There is a small village with nn people. Number these nn people from 11 to nn. Person 11 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 mm 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 nn.

The second line contains an integer, the number of nights mm.

Lines 33 to (m+2)(m + 2) describe each night. Line (i+2)(i + 2) describes night ii:
The line first contains an integer kik_i, meaning kik_i villagers came that night, followed by kik_i distinct integers ai,ja_{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.

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

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

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

1

Hint

Constraints

For all testdata, it is guaranteed that:

  • 1n1001 \leq n \leq 100, 1m501 \leq m \leq 50.
  • 2kin2 \leq k_i \leq n, 1ai,jn1 \leq a_{i, j} \leq n. 11 appears in ai,ja_{i, j} at least once.

Notes

Translated from COCI2006-2007 Regional Competition T1 BARD. Translation by @一扶苏一

Translated by ChatGPT 5