#P15299. [ROI 2012 Day 2] theatre 剧院始于演员

    ID: 17378 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2012ROI(俄罗斯)哈希表STL

[ROI 2012 Day 2] theatre 剧院始于演员

Background

Translation source: loj #5460. 「ROI 2012 Day 2」The Theatre Begins with the Actors.

Problem Description

Olympiad participants came to the Kazan theatre to watch a performance. There are NN actors in the play whom they do not know. In the theatre lobby, portraits of all actors in the troupe are displayed, and the whole troupe takes part in the performance, but the portraits have no names. The audience received a playbill that lists, for each act, the surnames of the actors participating in that act, but it does not state their roles.

A theatre fan, Vitaly, decided to find out what each actor mentioned in the playbill looks like. To do this, during the intermission after each act, he goes to the lobby and compares the portraits with the actors he has seen.

You need to write a program that, given the number of actors NN and the lists of surnames of actors participating in each of the MM acts, determines after which act it becomes possible for the first time to determine the correspondence between the surnames in the playbill and the portraits.

Input Format

The first line of the input file contains two natural numbers NN and MM (1<N≤100000,1≤M≤100000)(1 < N \leq 100000, 1 \leq M \leq 100000), representing the number of actors and the number of acts, respectively.

The next MM lines describe the acts. Each line starts with an integer KiK_i $(1 \leq K_i \leq N, K_1 + K_2 + \ldots + K_M \leq 100000)$, the number of actors participating in the ii-th act, followed by KiK_i distinct natural numbers (not exceeding NN), which are the surname IDs of the actors participating in this act. Adjacent numbers in a line are separated by spaces.

Output Format

Output one line containing NN integers separated by spaces. The ii-th integer indicates after which act it becomes possible for the first time to determine the correspondence between the ii-th actor and their portrait. If it is still impossible to determine the correspondence for some actor even after the performance ends, output 00 in that position.

3 3
2 1 2
2 3 2
2 1 2
2 2 1

5 3
3 1 2 3
3 2 3 1
2 1 3
0 3 0 0 0

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

Hint

In the first sample, three actors participate in a performance consisting of three acts. The first act has two actors, numbered 11 and 22. Since there are three actors in total, after the first act ends, it is possible to determine that the portrait of actor 33 corresponds to surname ID 33, so the third number in the output line is 11.

The second act has two actors, numbered 33 and 22. Since only actor 22 participates in both the first and the second act, after the second act ends, it is possible to determine their portrait. Also, since there are three portraits in total, after the second act ends it is possible to determine that the remaining portrait corresponds to actor 11. The third act does not affect the result.

Detailed additional constraints and scores for subtasks are given in the table below:

Subtask Score Additional Constraints
11 3030 N≤100N \leq 100, M≤100M \leq 100, K1+K2+…+KM≤100K_1 + K_2 + \ldots + K_M \leq 100
22 N≤10000N \leq 10000, M≤10000M \leq 10000, K1+K2+…+KM≤10000K_1 + K_2 + \ldots + K_M \leq 10000
33 4040 N≤100000N \leq 100000, M≤100000M \leq 100000, K1+K2+…+KM≤100000K_1 + K_2 + \ldots + K_M \leq 100000

Translated by ChatGPT 5