#P3876. [TJOI2010] 数字序列
[TJOI2010] 数字序列
Description
Consider a sequence of length over digits 0, 1, 2, 3. If it is a valid sequence, it must satisfy both of the following:
-
No adjacent pair appears as any pattern in {'00', '11', '22', '33', '02', '20', '23', '32', '13', '31'}.
-
The sequence satisfies constraints. Each constraint is of the form {p1, p2, ... pL}, meaning the values at positions are pairwise distinct. For example, the constraint {1, 5, 11} means the 1st, 5th, and 11th elements are all different.
Given , , and these constraints, determine whether such a valid sequence exists.
Input Format
The first line contains a positive integer , the number of test cases. For each test case, the first line contains two integers and as described above. Then there are lines, each describing one constraint: in the -th line, the first integer is the size of the constraint, followed by positive integers giving the positions in the -th constraint.
Output Format
Output lines. For each test case, print Yes if a valid sequence exists; otherwise, print No.
2
7 2
3 1 2 4
4 2 4 5 7
3 1
2 1 1
Yes
No
Hint
Constraints:
, , , , .
Time limit per test point: 1 second.
In the first sample, the sequence 0103012 is a valid sequence.
Translated by ChatGPT 5
京公网安备 11011102002149号