Score : $400$ points
We have $2N$ balls. Each ball has a color represented by an integer between $1$ and $N$ (inclusive). For each of the $N$ colors, there are exactly two balls of that color.
These balls are contained in $M$ cylinders placed perpendicularly to the floor. Initially, the $i$-th cylinder $(1 \leq i \leq M)$ contains $k_i$ balls, the $j$-th of which from the top $(1 \leq j \leq k_i)$ has the color $a_{i, j}$.
Your objective is to empty all $M$ cylinders by repeating the following operation.
Determine whether the objective is achievable.
Input is given from Standard Input in the following format:
$N$ $M$ $k_1$ $a_{1,1}$ $a_{1,2}$ $\ldots$ $a_{1,k_1}$ $k_2$ $a_{2,1}$ $a_{2,2}$ $\ldots$ $a_{2,k_2}$ $\hspace{2.1cm}\vdots$ $k_M$ $a_{M,1}$ $a_{M,2}$ $\ldots$ $a_{M,k_M}$
If the objective is achievable, print Yes
; otherwise, print No
.
2 2 2 1 2 2 1 2
Yes
The objective can be achieved as follows.
2 2 2 1 2 2 2 1
No
No operation can be done at all, which means it is impossible to achieve the objective of emptying the $M$ cylinders.