CF1483A.Basic Diplomacy

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

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.

阿列克谢有 nn 个朋友。他目前也在度假,因此有 mm 天时间来玩这款新爆火的合作类游戏!但由于是合作模式,阿列克谢在接下来的 mm 天中每天都需要一名队友。

在这些天中,每天都会有一部分朋友有空玩游戏,其余朋友则没空。每天,阿列克谢必须从当天有空的朋友中选择一人邀请其一起玩游戏(而他们当然总是同意)。然而,如果某位朋友被选中的次数严格超过 ⌈m2⌉\left\lceil\dfrac{m}{2}\right\rceil 次,那么所有其他朋友都会感到被冒犯。显然,阿列克谢不希望任何人感到被冒犯。

请帮助他安排每天的队友,使得没有任何人被选中的次数严格超过 ⌈m2⌉\left\lceil\dfrac{m}{2}\right\rceil 次。

输入格式

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

The first line of each test case contains two integers nn and mm (1≤n,m≤100 0001\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 (1≤ki≤n1\leq k_i\leq n), followed by kik_i distinct integers fi1f_{i1}, ..., fikif_{ik_i} (1≤fij≤n1\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 100 000100\,000. It's guaranteed that the sum of all kik_i over all days of all test cases doesn't exceed 200 000200\,000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10 0001 \le t \le 10\,000)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤100 0001\leq n, m\leq 100\,000),分别表示朋友的数量和游戏的天数。

接下来的 mm 行中,第 ii 行包含一个整数 kik_i(1≤ki≤n1\leq k_i\leq n),后跟 kik_i 个互不相同的整数 fi1f_{i1}, ..., fikif_{ik_i}(1≤fij≤n1\leq f_{ij}\leq n),以空格分隔——这些是第 ii 天可参与游戏的朋友的编号。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 100 000100\,000。同时保证所有测试用例中所有天数的 kik_i 总和不超过 200 000200\,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.

为每个测试用例输出一个答案。如果无法达成目标,则输出 "NO"。

否则,第一行输出 "YES",第二行输出 mm 个用空格分隔的整数 c1c_1, ..., cmc_m。其中每个 cic_i 表示第 ii 天所选择的朋友(因此必须是 fijf_{ij} 中的一个)。

任意数值出现次数不得超过 ⌈m2⌉\left\lceil\dfrac{m}{2}\right\rceil 次。若存在多个可行答案,输出任意一个即可。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页