#P16512. [GKS 2015 #C] gGames

    ID: 16489 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2015状压 DPGoogle Kick Start

[GKS 2015 #C] gGames

题目描述

The country of elves is planning to hold an elimination tournament, and there are 2N2^N elves who would like to take part. At the start of the tournament, they will be given unique ID numbers from 11 to 2N2^N, and the Elf President will line them up in some order.

The tournament is a series of matches between two elves, and every match has one winner and one loser (there are no ties). In the first round, the first elf in the line competes against the second elf in the line, the third elf competes against the fourth elf, and so on. After the first round, the 2N12^{N-1} elves who lost leave the line, and the 2N12^{N-1} elves who won remain where they are. Then, the remaining elves play the second round in the same way: the first remaining elf in the line competes against the second remaining elf in the line, the third remaining elf competes against the fourth remaining elf, and so on. After NN rounds, there will be only one elf remaining, and that elf is the winner.

MM of the elves are sensitive, which means that they will be very sad if they have to compete in matches against their friends during the games. Specifically, the iith elf will be sad if they have to compete with their friends in the first KiK_i rounds. (Note that friendship is not necessarily mutual: if one elf considers another elf to be a friend, the other elf does not necessarily consider that elf to be a friend.)

The Elf President wants to know: is there a way to specify the initial positions of all 2N2^N elves to guarantee that no elf will be sad, no matter what happens in the tournament?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of one line with two integers NN and MM, then MM sets of two lines each, in which the first line has integers EiE_i, KiK_i, and BiB_i for one elf, and the second has BiB_i integer ID numbers of that elf's friends.

输出格式

For each test case, output one line containing "Case #x: ", where x is the case number (starting from 1), followed by YES or NO.

3
1 1
1 1 1
2
2 2
1 1 1
2
3 1 1
4
3 3
1 2 2
3 4
2 2 2
5 6
7 1 1
8
Case #1: NO
Case #2: YES
Case #3: YES

提示

Limits

1T2001 \le T \le 200.

0M2N0 \le M \le 2^N.

1Ei2N1 \le E_i \le 2^N.

1KiN1 \le K_i \le N.

Msum(Bi)min(2×M,2N)M \le \text{sum}(B_i) \le \min(2 \times M, 2^N).

Small dataset (Test Set 1 - Visible)

1N31 \le N \le 3.

Large dataset (Test Set 2 - Hidden)

N=4N = 4.