100 atcoder#ABC216D. [ABC216D] Pair of Balls
[ABC216D] Pair of Balls
Score : points
Problem Statement
We have balls. Each ball has a color represented by an integer between and (inclusive). For each of the colors, there are exactly two balls of that color.
These balls are contained in cylinders placed perpendicularly to the floor. Initially, the -th cylinder contains balls, the -th of which from the top has the color .
Your objective is to empty all cylinders by repeating the following operation.
- Choose two different non-empty cylinders and remove the topmost ball from each of them. Here, the two balls removed must be of the same color.
Determine whether the objective is achievable.
Constraints
- $1 \leq a_{i,j} \leq N\ (1 \leq i \leq M,1 \leq j \leq k_i)$
- For every , there exists exactly two pairs of integers such that , , and .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
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.
- Choose the first and second cylinders to remove the topmost ball from each of them, which is allowed since the removed balls have the same color: .
- Choose the first and second cylinders to remove the topmost ball from each of them, which is allowed since the removed balls have the same color: .
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 cylinders.