#C2177. Matching Users with Common Interests

    ID: 45464 Type: Default 1000ms 256MiB

Matching Users with Common Interests

Matching Users with Common Interests

Given a list of users with their associated interests, your task is to find all pairs of users that share at least one common interest. For each pair, print the user IDs in increasing order. If no such pair exists, output "NO PAIRS".

Details:

  • The first line of input contains an integer \( n \) which represents the number of users.
  • The next \( n \) lines each describe a user. Each line begins with the user's ID (an integer) followed by one or more interests (each interest is a single word).

Note: The generated formula is in \( \LaTeX \) format. For example, the number of users is given by \( n \), and you may refer to a user's line as a sequence where the first token is the ID and the rest are the interests.

inputFormat

The input is read from stdin. The first line contains an integer \( n \), indicating the number of users. The next \( n \) lines each contain a user's information: the first token is the user ID, followed by one or more interests separated by spaces.

outputFormat

Output the pairs of user IDs sharing at least one common interest. Each pair should be printed on a separate line as "user1 user2", where \( user1 < user2 \). The pairs must be sorted in increasing order first by the first ID and then by the second. If there is no pair of users sharing a common interest, output a single line containing "NO PAIRS".

## sample
3
1 hiking coding
2 cooking hiking
3 cooking
1 2

2 3

</p>