#abc216d. D - Pair of Balls
D - Pair of Balls
Score : points
问题描述
我们有 个球。每个球的颜色由一个介于 和 (包含)之间的整数表示。对于每种颜色,恰好有两个球是该颜色。
这些球被放在 个垂直于地面放置的圆柱体中。最初,第 个圆柱体 包含 个球,其中从上到下的第 个球 的颜色为 。
你的目标是通过重复以下操作来清空所有 个圆柱体。
- 选择两个不同的非空圆柱体,并从它们各自顶部移除最上面的球。这里,所移除的两个球必须是同一颜色。
确定这个目标是否可以实现。
以上为通义千问 qwen-max 翻译,仅供参考。
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
.
Sample Input 1
2 2
2
1 2
2
1 2
Sample Output 1
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: .
Sample Input 2
2 2
2
1 2
2
2 1
Sample Output 2
No
No operation can be done at all, which means it is impossible to achieve the objective of emptying the cylinders.
update @ 2024/3/10 09:35:02