P7234 [JSOI2014] Opera Performance

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 $n$ actors and has held $m$ performances. All actors are numbered from $1$ to $n$, and in the $i$-th performance, there are $k_i$ actors participating. JYY has seen photos of all $n$ actors (so he knows the faces of these $n$ actors), and he has also seen the roster of actors (so he knows the names of these $n$ actors; assume there are no duplicate names). He has also carefully watched all $m$ 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 $m$ performances, can he match every actor’s name and face one by one?

Input Format

The first line contains two positive integers $n$ and $m$. In the next $m$ lines, each line first contains an integer $k_i$, followed by $k_i$ distinct integers between $1$ and $n$, indicating the actor numbers participating in this performance.

Output Format

Output one line with $n$ integers. The $i$-th integer $a_i$ means that after the $a_i$-th performance, JYY can match actor number $i$ with their face. If after all $m$ performances JYY still cannot recognize this actor, then $a_i$ is $0$.

Explanation/Hint

### Sample Explanation 1 In each performance, it is possible to determine the face of one actor, and actor $4$ 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 $4$. ### Constraints $1\leq n,m\leq 10^5,\sum\limits_{i=1}^{n}k_i\leq 10^5$。 Translated by ChatGPT 5