#K51087. Verify and Suggest Friends
Verify and Suggest Friends
Verify and Suggest Friends
You are given a set of users along with their hobbies. Each user is represented by a unique user ID (a string) followed by a list of hobby IDs (integers). Your task is to verify if a target user exists among these users. If the target user exists, print "User found" followed, in new lines, by the list of friends who share at least one common hobby with the target user (if any). If the target user does not exist, output "User not found".
Input Format: The input is read from standard input (stdin). The first line contains the target user ID. The second line contains a single integer n representing the number of users. The following n lines each contain a user's information. The first token is the user ID (a string) followed by one or more integers representing the user's hobbies. Tokens are space separated.
Output Format: Output to standard output (stdout). If the target user is found, print "User found" on the first line. If the target user has friends (i.e. other users that share at least one hobby with the target user), print each friend’s user ID on a new line in the order they appear in the input. If there are no such friends, simply print "User found". If the target user is not found, output "User not found".
Note: Two users are considered friends if the intersection of their hobbies is non-empty. In mathematical terms, if H_a and H_b denote the hobby sets of two users, they are friends if \(H_a \cap H_b \neq \emptyset\).
inputFormat
The first line contains a target user ID (a string). The second line contains an integer n indicating the number of users. Each of the following n lines contains a user's details: the user's ID followed by one or more integers representing hobbies, all separated by spaces.
outputFormat
If the target user is not found, output exactly "User not found". If found, output "User found" on the first line. If the target user has any friends (i.e. users sharing at least one common hobby with the target), list each friend’s user ID on a separate line following "User found". If no friends are found, output only "User found".
## samplealice
4
alice 1 2 3
bob 2 4
charlie 5 6
dave 1 3 4
User found
bob
dave
</p>