CF1483A.Basic Diplomacy

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Aleksey has nn friends. He is also on a vacation right now, so he has mm days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these mm days.

On each of these days some friends will be available for playing, and all others will not. On each day Aleksey must choose one of his available friends to offer him playing the game (and they, of course, always agree). However, if any of them happens to be chosen strictly more than m2\left\lceil\dfrac{m}{2}\right\rceil times, then all other friends are offended. Of course, Aleksey doesn't want to offend anyone.

Help him to choose teammates so that nobody is chosen strictly more than m2\left\lceil\dfrac{m}{2}\right\rceil times.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t100001 \le t \le 10\,000 ). Description of the test cases follows.

The first line of each test case contains two integers nn and mm ( 1n,m1000001\leq n, m\leq 100\,000 ) standing for the number of friends and the number of days to play, respectively.

The ii -th of the following mm lines contains an integer kik_i ( 1kin1\leq k_i\leq n ), followed by kik_i distinct integers fi1f_{i1} , ..., fikif_{ik_i} ( 1fijn1\leq f_{ij}\leq n ), separated by spaces — indices of available friends on the day ii .

It is guaranteed that the sums of nn and mm over all test cases do not exceed 100000100\,000 . It's guaranteed that the sum of all kik_i over all days of all test cases doesn't exceed 200000200\,000 .

输出格式

Print an answer for each test case. If there is no way to achieve the goal, print "NO".

Otherwise, in the first line print "YES", and in the second line print mm space separated integers c1c_1 , ..., cmc_m . Each cic_i must denote the chosen friend on day ii (and therefore must be one of fijf_{ij} ).

No value must occur more than m2\left\lceil\dfrac{m}{2}\right\rceil times. If there is more than one possible answer, print any of them.

输入输出样例

  • 输入#1

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

    输出#1

    YES
    1 2 1 1 2 3 
    NO
首页