Waif Until Dark
Time limit2sMemory limit512 MB
Match children to toys they like, with a per-category cap on how many toys of each category can be used, and maximize satisfied children.
- Level
Medium7 of 10
- Topics
- Graph, BFS, Greedy, Implementation
- Solved
- No attempts yet
Problem
Waif Until Dark is a daycare center for households where both parents work during the day. To keep the children busy, the center has a set of toys they can play with. Some toys belong to one category, such as sports toys, musical toys, or dolls. To limit wear on those toys, the teachers allow only a fixed number of toys from each category during playtime. Children do not all like the same toys, so handing every child a toy they like is not always possible.
A child receives at most one toy, and a toy goes to at most one child. A child is satisfied when the child receives a toy from their own list. Find the largest number of children that can be satisfied at the same time.
Input
The first line contains the number of children , the number of toys , and the number of toy categories (, ). Children and toys are numbered starting at 1.
Each of the next lines has the form (, ). The th of these lines means that child is willing to play with toys through .
Each of the next lines has the form (, ). The th of these lines means that toys through belong to category and that at most toys of that category can be used.
A toy belongs to at most one category. A toy that never appears on those lines has no category, and all such toys can be used with no limit. No toy number appears twice on the same line.
Output
Print the largest number of children that can be satisfied with a toy they like.