#P2417. 课程

课程

Description

There are nn students and mm classrooms. For classroom ii, there are kik_i students who can take a class there, with indices pi,jp_{i,j}. 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 TT, where T10T \leq 10.

For each test case, the first line contains two integers m,nm, n (note the input order). Then follow mm lines: the first number is kik_i, followed by kik_i numbers pi,jp_{i,j}, indicating that student pi,jp_{i,j} can take a class in classroom ii.

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: n2×104n \leq 2 \times 10^4, m2×104m \leq 2 \times 10^4, T10T \leq 10.

Translated by ChatGPT 5