#548
Unrated
Bracelet Crossings
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie the cow enjoys arts and crafts. In her free time, she has made NN (1N501\le N\le 50) bracelets, conveniently numbered 1N1 \ldots N. The iith bracelet is painted color ii out of a set of NN different colors. After constructing the bracelets, Bessie placed them on a table for display (which we can think of as the 2D plane). She was careful to arrange the bracelets to satisfy the following three conditions:

Every bracelet was a single closed polygonal chain -- a series of vertices (points) connected sequentially by line segments, where the first and last points are the same (Feel welcome to consult the wikipedia page for more detail: polygonal chain), No bracelet intersected itself (this corresponds to a "simple" polygonal chain); andNo two bracelets intersected.

Unfortunately, right after Bessie arranged the bracelets in such a careful manner, Farmer John drove by in his tractor, shaking the table and causing the bracelets to shift around and possibly break into multiple (not necessarily closed or simple) polygonal chains! Afterward, Bessie wanted to check whether the three conditions above still held. However, it was dark, so she couldn't see the bracelets anymore.

Fortunately, Bessie had a flashlight. She chose MM (1M501\le M\le 50) vertical lines x=1,x=2,,x=Mx=1, x=2, \ldots, x=M and for each line, she swept the beam of the flashlight along that line from y=y=-\infty to y=y=\infty, recording the colors of all bracelets she saw in the order they appeared. Luckily, no beam crossed over any vertex of any polygonal chain or two line segments at the same time. Furthermore, for each beam, every color that appeared appeared exactly twice.

Can you help Bessie use this information to determine whether it is possible that the bracelets still satisfy all three of the conditions above?

입력

Each input case contains TT sub-cases (1T501 \leq T \leq 50) that must all solved independently to solve the full input case. Consecutive test cases are separated by newlines.

The first line of the input contains TT. Each of the TT sub-test cases then follow.

The first line of each sub-test case contains two integers NN and MM. Each sub-test case then contains MM additional lines. For each ii from 11 to MM, the ii-th additional line contains an integer kik_i (0ki2N0\le k_i\le 2N, kik_i even), followed by kik_i integers ci1,ci2,,cikic_{i1}, c_{i2},\ldots, c_{ik_i} (cij[1,N]c_{ij}\in [1,N], every cijc_{ij} appears zero or two times). This means that when Bessie swept her flashlight from (i,)(i,-\infty) to (i,)(i,\infty), she encountered the colors ci1,ci2,,cikic_{i1}, c_{i2},\ldots, c_{ik_i} in that order.

출력

For each sub-test case, print YES if it is possible for the three conditions above to be satisfied. Otherwise, print NO.

예제 입력 1

5

1 2
2 1 1
2 1 1

1 3
2 1 1
0
2 1 1

2 1
4 1 2 1 2

4 2
6 1 2 2 3 3 1
6 1 2 4 4 2 1

2 2
4 1 1 2 2
4 2 2 1 1

예제 출력 1

YES
NO
NO
YES
NO

점수

Test case 2 satisfies N=1N = 1.Test cases 3-5 satisfy N=2N=2.Test cases 6-8 satisfy M=1M=1.Test cases 9-14 satisfy M=2M=2.Test cases 15-20 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.