問題一覧 > 通常問題

No.2148 Solo UNO

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 55
作問者 : ei1333333 / テスター : Luzhiled beet
お気に入りにしたユーザー ProblemId : 8799 / 自分の提出
問題文最終更新日: 2022-12-04 21:29:34
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2022 (順位表) の他の問題:

Problem Statement

Hikari has $N$ cards. Each card has one of the colors B,G,R, and has $1$ value written on it.

The color of the $i\ (1 \leq i \leq N)$-th card is $C_i$, and its value is $D_i$. It is guaranteed that no two cards have both the same color and the same value.

After first playing any card of her choice, she repeatedly performs the operation of playing a card that has the same color or the same value as the card played immediately before.

Determine whether she can play all the cards.

For each input file, answer $T$ independent test cases.

Constraints

  • $1 \leq T \leq 1000$
  • $1 \leq N \leq 2 \times 10^5$
  • $C_i$ is one of the characters B,G,R
  • $1 \leq D_i \leq N$
  • If $i \neq j$, then $(C_i, D_i) \neq (C_j, D_j)$
  • The sum of $N$ is at most $2 \times 10^5$
  • $T, N, D_i$ are integers

Input

The input is given from standard input in the following format.

$T$
$Case_1$
$Case_2$
$:$
$Case_T$

The $i$-th test case $Case_i (1 \leq i \leq N)$ is given in the following format.

$N$
$C_1$ $D_1$
$C_2$ $D_2$
$:$
$C_N$ $D_N$

Output

Output consists of $T$ lines.

On the $i (1 \leq i \leq T)$-th line, for the $i$-th test case, output YES if all the cards can be played, and NO otherwise.

Sample

Sample 1
Input
3
7
R 1
R 2
R 3
G 1
G 2
B 2
B 3
3
B 1
G 2
R 3
3
B 1
B 2
B 3
Output
YES
NO
YES

In test case number $1$, for example, she plays card number $1$ and then plays cards in the order $2, 3, 7, 6, 5, 4$.

In test case number $2$, she can only play one of the cards.

In test case number $3$, for example, she plays card number $1$ and then plays cards in the order $2, 3$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。