Herding Cats

시간 제한2초메모리 제한2048 MB

요약
각 고양이가 멈춰야 할 화분 번호와 좋아하는 캣닙 종류가 주어질 때, 모든 고양이가 지정된 화분에서 멈추도록 m개의 식물을 배치할 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
그리디, 정렬, 구현
정답자
아직 제출이 없습니다

문제

You are opening a cat cafe in Baku and would like to take a promotional photograph of all the cats sitting in the front window. Unfortunately, getting cats to do what you want is a famously hard problem. But you have a plan: you have bought a collection of mm catnip plants, each of a different variety, knowing that each cat likes some of these varieties. There is a row of mm pots in the window, numbered 11 to mm in order, and you will place one plant in each pot. Each cat will then be persuaded (by means of a toy on a string) to walk along the row of pots from 11 to mm. As soon as a cat reaches a pot with a catnip plant that it likes, it will stop there, even if there already are other cats at that plant.

Figure F.1: One possible plant ordering for the first sample test case.

You know which pot you would like each cat to stop beside. Can you find a way in which to place the plants in the pots to achieve this?

입력

The first line of input contains an integer tt (1≤t≤10,0001 ≤ t ≤ 10\\, 000), which is the number of test cases. The descriptions of tt test cases follow.

The first line of each test case contains two integers nn and mm, where nn (1≤n≤2⋅1051 ≤ n ≤ 2 \cdot 10^5) is the number of cats, and mm (1≤m≤2⋅1051 ≤ m ≤ 2 \cdot 10^5) is the number of catnip plants (and also the number of pots). Catnip plants are numbered from 11 to mm.

The following nn lines each describe one cat. The line starts with two integers pp and kk, where pp (1≤p≤m1 ≤ p ≤ m) is the pot at which the cat should stop, and kk (1≤k≤m1 ≤ k ≤ m) is the number of catnip plants the cat likes. The remainder of the line contains kk distinct integers, which are the numbers of the plants that the cat likes.

Over all test cases, the sum of nn is at most 2⋅1052 \cdot 10^5, the sum of mm is at most 2⋅1052 \cdot 10^5, and the sum of all kk is at most 5⋅1055 \cdot 10^5.

출력

For each test case, output either yes if it is possible to arrange the catnip plants as described above, or no if not.

예제1

  1. 예제 1

    입력
    2
    3 5
    2 2 1 5
    2 3 1 4 5
    4 2 3 4
    3 5
    2 2 1 5
    2 3 1 4 5
    5 2 3 4
    
    예상 출력
    yes
    no