#P6479. [CRCI2006-2007] BARD
[CRCI2006-2007] BARD
Problem Description
There is a small village with people. Number these people from to . Person 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 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 .
The second line contains an integer, the number of nights .
Lines to describe each night. Line describes night :
The line first contains an integer , meaning villagers came that night, followed by distinct integers , 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:
- , .
- , . appears in at least once.
Notes
Translated from COCI2006-2007 Regional Competition T1 BARD. Translation by @一扶苏一。
Translated by ChatGPT 5