#P2417. Classroom Assignment
Classroom Assignment
Classroom Assignment
You are given n students and m classrooms. In the ith classroom, there are \(k_i\) students available, with their IDs given as \(p_{i,1}, p_{i,2}, \dots, p_{i,k_i}\). Each student is available in at least one classroom, and each student can attend only one classroom.
Your task is to determine whether there exists an assignment of students to classrooms such that every classroom gets at least one student. If such an assignment exists, output YES
; otherwise, output NO
.
Note: A student can only be assigned to one classroom even if they are available in multiple classrooms.
inputFormat
The first line contains two integers n
and m
representing the number of students and the number of classrooms, respectively.
The following m
lines describe each classroom. The ith line starts with an integer ki
, indicating the number of students who can attend classroom i
, followed by ki
integers \(p_{i,1}, p_{i,2}, \dots, p_{i,k_i}\), representing the IDs of the students available for that classroom.
Note: Students are numbered from 1 to n. It is guaranteed that every student appears in at least one classroom list.
outputFormat
If there is a valid assignment such that every classroom gets at least one student (with each student assigned to at most one classroom), output YES
. Otherwise, output NO
.
sample
3 2
2 1 2
2 2 3
YES
</p>