X Olympiad in Informatics 2002/2003

Problem: Treasure

Author: Adam Borowski

King Byteasar had hidden a treasure in his castle, and he kept his hiding place in secret. However, whenever he went to war he was afraid he could die and the treasure would get lost. Therefore he chose trustworthy guards and confided partial information needed to find the treasure to each of them. Next he ordered them to go to the underground vaults that lie under the castle and to walk there using the righthand rule. The vaults were connected by corridors. The corridors did not cross outside the vaults but they could run under other corridors. There were no corridors leading to the same vault they led off. The righthand rule stated that a guard after entering a vault left it by the next corridor to the right. The guards were appointed different starting positions at entrances to corridors. It might happen that many guards started from the same vault, unless they were entering the same corridor.
The king knew that until he fell or returned from war all guards would loyally follow his orders. However, he was aware that whenever any two or more guards met in some vault they could not resist sharing all the information they knew about the treasure. The guards were not selfish and they shared information even if some of them would not learnt anything new. If some guards started from the same vault they immediately shared the information they initially knew. If they passed one another in corridors, however, they did not talk.
The king pondered if the treasure would still be secure when he safely returned from war. He wanted to know which guards might obtain all the information needed to find the treasure.
In the (n + 2)nd line there are written two integers k and l, 1 <= k <= 100, 1 <= l <= 100, where k is the number of guards, and l is the number of pieces of information needed to find the treasure. The guards are numbered from 1 to k. The pieces of information concerning the treasure are numbered from 1 to l. The guards are described in the following k lines (the ith guard is described in the (i + n + 2)nd line). Each of those lines consists of integers separated by single spaces. The first integer in a line is the number of the vault the corresponding guard starts from. The second number is the number of the vault the guard goes to first. The third number, m_{i}, is the number of pieces of information concerning the treasure the ith guard initially knows, 0 <= m_{i} <= l. The following m_{i} integers in the line are the numbers of the pieces of information initially known to the ith guard.
4 3 2 3 3 4 4 1 2 1 3 3 1 3 4 3 1 4 2 1 2 1 1 3 3 3 4 1 4 2 2 3 3 1 2 1 2 3 4 2 3 4the correct answer is in the following output:
2 2 3