Choosing a Bias
Time limit2sMemory limit256 MB
Given N friends and M members, each friend lists acceptable members; decide if a distinct member can be assigned to each of the N friends.
- Level
Medium7 of 10
- Topics
- Graph, String, Hash map, Brute force
- Solved
- No attempts yet
Problem
Heukseok and Sangdo like CAU (Complete & Awesome Unit), the best girl group in the country. In CAU there are several members that Heukseok likes and several members that Sangdo likes.
Heukseok and Sangdo want to pick their bias, the member they like most. However, because of the friendship between the two friends, they are not allowed to pick the same member as their bias.
So, to keep the friends' friendship, we want to assign each of them one bias member, all distinct.
Write a program that determines whether their friendship can be kept.
Input
The first line gives the number of friends and the number of girl group members . ()
The next lines each give the name of a girl group member. A member's name consists only of uppercase English letters and is at most 100 characters long.
The next lines each give, for one friend, the number of members they like () followed by the names of the girl group members they like, separated by spaces.
Output
The first line reports whether the friends' friendship can be kept. Print YES if it can, and NO if it cannot.
If the friendship cannot be kept, the second line prints the maximum number of members the friends as a whole can like without any overlap.