A14151 | Basic Diplomacy
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $\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 $\left\lceil\dfrac{m}{2}\right\rceil$ times.
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 $\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 $\left\lceil\dfrac{m}{2}\right\rceil$ times.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10\,000$ ). Description of the test cases follows.
The first line of each test case contains two integers $n$ and $m$ ( $1\leq n, m\leq 100\,000$ ) 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 $k_i$ ( $1\leq k_i\leq n$ ), followed by $k_i$ distinct integers $f_{i1}$ , ..., $f_{ik_i}$ ( $1\leq f_{ij}\leq 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 $100\,000$ . It's guaranteed that the sum of all $k_i$ over all days of all test cases doesn't exceed $200\,000$ .
The first line of each test case contains two integers $n$ and $m$ ( $1\leq n, m\leq 100\,000$ ) 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 $k_i$ ( $1\leq k_i\leq n$ ), followed by $k_i$ distinct integers $f_{i1}$ , ..., $f_{ik_i}$ ( $1\leq f_{ij}\leq 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 $100\,000$ . It's guaranteed that the sum of all $k_i$ over all days of all test cases doesn't exceed $200\,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 $m$ space separated integers $c_1$ , ..., $c_m$ . Each $c_i$ must denote the chosen friend on day $i$ (and therefore must be one of $f_{ij}$ ).
No value must occur more than $\left\lceil\dfrac{m}{2}\right\rceil$ times. If there is more than one possible answer, print any of them.
Otherwise, in the first line print "YES", and in the second line print $m$ space separated integers $c_1$ , ..., $c_m$ . Each $c_i$ must denote the chosen friend on day $i$ (and therefore must be one of $f_{ij}$ ).
No value must occur more than $\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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted