CF1483A.Basic Diplomacy
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Aleksey has n friends. He is also on a vacation right now, so he has m days to play this new viral cooperative game! But since it's cooperative, Aleksey will need one teammate in each of these m 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 ⌈2m⌉ 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 ⌈2m⌉ times.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤10000 ). Description of the test cases follows.
The first line of each test case contains two integers n and m ( 1≤n,m≤100000 ) standing for the number of friends and the number of days to play, respectively.
The i -th of the following m lines contains an integer ki ( 1≤ki≤n ), followed by ki distinct integers fi1 , ..., fiki ( 1≤fij≤n ), separated by spaces — indices of available friends on the day i .
It is guaranteed that the sums of n and m over all test cases do not exceed 100000 . It's guaranteed that the sum of all ki over all days of all test cases doesn't exceed 200000 .
输出格式
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 m space separated integers c1 , ..., cm . Each ci must denote the chosen friend on day i (and therefore must be one of fij ).
No value must occur more than ⌈2m⌉ 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