QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100

#15416. 评测问题

통계

NWRRC 的裁判们想出了 $n$ 道关于类似主题的题目,并决定在连续的 $n$ 年里每年使用一道题。唯一的问题是:应该以什么顺序使用它们?

每个题目的名称由两个单词组成。如果两个名称的第一个单词相同,或者第二个单词相同,我们就称这两个名称是相似的。例如,eight shapedeight connected 是相似的,而 hello worldworld hello 则不是。

裁判们决定执行以下规则:在第一年,他们任意选择一道题。在随后的每一年中,如果存在与前一年题目名称相似且尚未使用的题目,他们必须选择其中之一;否则,他们可以选择任何尚未使用的题目。

给你按使用时间顺序排列的题目名称。请判断裁判们是否正确遵守了上述规则,或者他们是否犯了错误。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 10^4$)。接下来是测试用例的描述。

每个测试用例的第一行包含一个整数 $n$,表示题目的数量 ($2 \le n \le 10^5$)。

接下来的 $n$ 行中,第 $i$ 行按时间顺序包含第 $i$ 个题目的名称:由两个单词组成,每个单词包含至少 1 个且最多 10 个英文小写字母。所有题目名称均不相同。

保证所有测试用例中 $n$ 的总和不超过 $10^5$。

输出格式

对于每个测试用例,如果裁判正确遵守了规则,则输出 "Yes",否则输出 "No"。

样例

输入样例 1

3
4
k shaped
h shaped
eight shaped
eight connected
3
k shaped
eight connected
eight shaped
4
judging problem
judging logic
binary problem
logic problem

输出样例 1

Yes
No
Yes

说明

在第一个测试用例中,每个后续的题目名称都与前一个相似。

在第二个测试用例中,裁判在第二年本应该选择 "eight shaped"。

在第三个测试用例中,"binary problem" 和 "logic problem" 都与 "judging logic" 不相似;裁判在第三年可以选择这两个题目中的任意一个。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.