#P2417. 课程
课程
Description
There are students and classrooms. For classroom , there are students who can take a class there, with indices . Each student has at least one classroom they can attend, and each student can attend only one classroom.
Determine whether there exists an assignment such that each classroom has at least one student. If it is possible, output YES; otherwise, output NO.
Input Format
The first line contains the number of test cases , where .
For each test case, the first line contains two integers (note the input order). Then follow lines: the first number is , followed by numbers , indicating that student can take a class in classroom .
Output Format
For each test case, output one string YES or NO, indicating whether there exists a valid assignment for the corresponding testdata.
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
YES
NO
Hint
Constraints: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号