#C7822. Favorite Movies Recommendation
Favorite Movies Recommendation
Favorite Movies Recommendation
Given a list of favorite movies for each person and their friendship relationships, your task is to generate a list of recommended movies for a specified person. A movie is recommended if it is liked by at least one of the person's friends but not by the person themselves.
The recommendation list should be sorted using the following procedure:
- Sort the movies by the frequency (number of friends who like the movie) in descending order.
- If two movies have the same frequency, sort them by their title in descending lexicographical order.
Note: The sorting method used in the reference solution first sorts by frequency in descending order and by movie title in ascending order, and then reverses the entire list, which effectively produces the above ordering.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers n and id, separated by a space, where n is the number of persons and id is the target person's id.
- The next n lines each describe the favorite movies of a person. Each of these lines begins with an integer m (the number of movies), followed by m strings (movie titles without spaces).
- The following n lines describe the friendship relationships. Each of these lines starts with an integer k (the number of friends), followed by k integers representing the ids of the friends.
All input values are separated by whitespace.
outputFormat
The output is a single line written to standard output (stdout) containing the recommended movie titles separated by a single space. If there are no recommended movies, output an empty line.
## sample4 0
2 A B
2 B C
3 A D E
2 C D
2 1 2
2 0 3
2 0 3
2 1 2
E D C