Logo
(追記) (追記ここまで)

35027번 - Judging Problem 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB555100.000%

문제

The judges of NWRRC came up with $n$ problems on a similar topic and decided to use them for $n$ consecutive years, one problem per year. The only question was: in what order should they be used?

Each problem's name consists of two words. Let's call two names similar if either their first words are the same or their second words are the same. For example, eight shaped and eight connected are similar, while hello world and world hello are not.

The judges decided to implement the following rule: in the first year, they chose a problem arbitrarily. In every subsequent year, if there was a problem with a name similar to the previous year's problem that was still unused, they chose one of such problems; otherwise, they chose any unused problem.

You are given the names of the problems in chronological order of their use. Determine whether the judges correctly followed the rule above, or if they made a mistake.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$ (1ドル \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains a single integer $n,ドル denoting the number of problems (2ドル \le n \le 10^5$).

The $i$-th of the following $n$ lines contains the name of the $i$-th problem in chronological order: two words consisting of at least 1ドル$ and at most 10ドル$ lowercase English letters each. All problem names are distinct.

It is guaranteed that the sum of $n$ over all test cases does not exceed 10ドル^5$.

출력

For each test case, print "Yes" if the judges followed the rule correctly, and "No" otherwise.

제한

예제 입력 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

노트

In the first test case, each subsequent problem name is similar to the previous one.

In the second test case, the judges should have chosen "eight shaped" for the second year.

In the third test case, neither "binary problem" nor "logic problem" is similar to "judging logic"; the judges could have chosen either of those problems for the third year.

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > ICPC 2025-2026 Northwestern Russia Regional Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /