#P7234. [JSOI2014] 歌剧表演

[JSOI2014] 歌剧表演

Description

The artsy youth JYY really likes watching opera performances.

JYY knows what all the actors look like and also knows all their names, but he cannot match names to faces. JYY hopes that one day he can figure out exactly who each actor is.

The JSOI opera troupe has a total of nn actors and has held mm performances. All actors are numbered from 11 to nn, and in the ii-th performance, there are kik_i actors participating.

JYY has seen photos of all nn actors (so he knows the faces of these nn actors), and he has also seen the roster of actors (so he knows the names of these nn actors; assume there are no duplicate names). He has also carefully watched all mm performances: in each performance, JYY knows which actors participated in this show and can tell their faces apart.

Now JYY wants to know: after watching these mm performances, can he match every actor’s name and face one by one?

Input Format

The first line contains two positive integers nn and mm.

In the next mm lines, each line first contains an integer kik_i, followed by kik_i distinct integers between 11 and nn, indicating the actor numbers participating in this performance.

Output Format

Output one line with nn integers. The ii-th integer aia_i means that after the aia_i-th performance, JYY can match actor number ii with their face.

If after all mm performances JYY still cannot recognize this actor, then aia_i is 00.

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

Hint

Sample Explanation 1

In each performance, it is possible to determine the face of one actor, and actor 44 is the only one who never participated in any performance. Since JYY already knew the faces of all actors at the beginning, after the third performance JYY can also confirm the face of actor 44.

Constraints

$1\leq n,m\leq 10^5,\sum\limits_{i=1}^{n}k_i\leq 10^5$。

Translated by ChatGPT 5