#K34482. Maximum Student Presentations

    ID: 25319 Type: Default 1000ms 256MiB

Maximum Student Presentations

Maximum Student Presentations

You are given a set of students and a set of available time slots. Each student has a list of time slots when they are available to present. Each time slot can be assigned to at most one student. Your task is to determine the maximum number of students that can be scheduled for a presentation.

This problem can be modeled as a bipartite matching problem. One partition represents the students and the other represents the time slots. An edge exists between a student and a time slot if the student is available during that slot. Use the Hopcroft–Karp algorithm (or any efficient matching algorithm) to compute the maximum matching.

Note that even though a list of available time slots is provided, every time slot from 1 to m is considered available. The available time slots list is given for completeness and consistency with the input format.

Input and output details are described below.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains two integers n and m, where n is the number of students and m is the number of available time slots.
  • The next n lines each describe a student's available time slots. Each of these lines starts with an integer k (the number of slots for that student), followed by k integers representing the time slots during which the student is available.
  • The final line contains m integers representing the available time slots. (Note: these slots are typically the integers from 1 to m.)

All tokens are separated by spaces.

outputFormat

Output a single integer to standard output (stdout) denoting the maximum number of students that can be scheduled for a presentation.

## sample
3 5
2 1 2
3 2 3 4
1 5
5 1 2 3 4 5
3