codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1482C.md (2282B)


      1 Source: https://codeforces.com/problemset/problem/1482/C
      2 
      3 C. Basic Diplomacy
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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.
     24 
     25 Help him to choose teammates so that nobody is chosen strictly more than $\left\lceil\dfrac{m}{2}\right\rceil$ times.
     26 
     27 Input
     28 
     29 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.
     30 
     31 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.
     32 
     33 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$.
     34 
     35 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$.
     36 
     37 Output
     38 
     39 Print an answer for each test case. If there is no way to achieve the goal, print "NO".
     40 
     41 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}$).
     42 
     43 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.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 2
     51 4 6
     52 1 1
     53 2 1 2
     54 3 1 2 3
     55 4 1 2 3 4
     56 2 2 3
     57 1 3
     58 2 2
     59 1 1
     60 1 1
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 YES
     67 1 2 1 1 2 3 
     68 NO
     69 ```