#P15299. [ROI 2012 Day 2] theatre 剧院始于演员
[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 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 and the lists of surnames of actors participating in each of the 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 and , representing the number of actors and the number of acts, respectively.
The next lines describe the acts. Each line starts with an integer $(1 \leq K_i \leq N, K_1 + K_2 + \ldots + K_M \leq 100000)$, the number of actors participating in the -th act, followed by distinct natural numbers (not exceeding ), 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 integers separated by spaces. The -th integer indicates after which act it becomes possible for the first time to determine the correspondence between the -th actor and their portrait. If it is still impossible to determine the correspondence for some actor even after the performance ends, output 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 and . Since there are three actors in total, after the first act ends, it is possible to determine that the portrait of actor corresponds to surname ID , so the third number in the output line is .
The second act has two actors, numbered and . Since only actor 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 . 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 |
|---|---|---|
| , , | ||
| , , | ||
| , , |
Translated by ChatGPT 5