#C11219. Common Friends

    ID: 40511 Type: Default 1000ms 256MiB

Common Friends

Common Friends

You are given the friendship data of several users. Each user is assigned an ID from 0 to n-1. For each user, you are provided with the list of their friends. Your task is to find the common friends between two specified users and output them in ascending order.

The input will provide the number of users, followed by each user’s friend list. Each friend list starts with an integer representing the number of friends, followed by the friend IDs. After the lists, two integers are given representing the user IDs for which the common friends are to be computed.

In other words, if we denote the friend list of user i as F_i, you need to output the sorted list (in increasing order) of elements of
\( F_{user\_id\_1} \cap F_{user\_id\_2} \)

If there are no common friends, output an empty line.

inputFormat

The first line contains an integer n representing the number of users.

The following n lines each start with an integer k denoting the number of friends for the user, followed by k integers representing the IDs of the friends.

The last line contains two integers, user_id_1 and user_id_2, separated by space.

Example:

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

outputFormat

Output the common friends of the two given users in ascending order, separated by a single space. If there are no common friends, output an empty line.

Example:

1
## sample
4
3 1 2 3
2 0 3
1 0
2 0 1
0 3
1