#abc247b. B - Unique Nicknames

B - Unique Nicknames

Score : 200200 points

问题描述

NN 名编号为 Person 11、Person 22\dots 和 Person NN 的人。其中,编号为 ii 的人拥有一个姓氏 sis_i 和一个名字 tit_i

考虑为这 NN 名人每人分配一个昵称。对于编号为 ii 的人,其昵称 aia_i 应满足以下所有条件:

  • aia_i 必须与该人的姓氏或名字相同,即 ai=sia_i = s_i 或/和 ai=tia_i = t_i 成立。
  • aia_i 不得与任何其他人的姓氏和名字相同。换句话说,对于所有满足 1jN1 \leq j \leq Niji \neq j 的整数 jj,都有 aisja_i \neq s_j 以及 aitja_i \neq t_j 成立。

是否可能为所有 NN 名人分配昵称?如果可以,则输出 Yes;否则,输出 No

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN people numbered Person 11, Person 22, \dots, and Person NN. Person ii has a family name sis_i and a given name tit_i.

Consider giving a nickname to each of the NN people. Person ii's nickname aia_i should satisfy all the conditions below.

  • aia_i coincides with Person ii's family name or given name. In other words, ai=sia_i = s_i and/or ai=tia_i = t_i holds.
  • aia_i does not coincide with the family name and the given name of any other person. In other words, for all integer jj such that 1jN1 \leq j \leq N and iji \neq j, it holds that aisja_i \neq s_j and aitja_i \neq t_j.

Is it possible to give nicknames to all the NN people? If it is possible, print Yes; otherwise, print No.

Constraints

  • 2N1002 \leq N \leq 100
  • NN is an integer.
  • sis_i and tit_i are strings of lengths between 11 and 1010 (inclusive) consisting of lowercase English alphabets.

Input

Input is given from Standard Input in the following format:

NN

s1s_1 t1t_1

s2s_2 t2t_2

\vdots

sNs_N tNt_N

Output

If it is possible to give nicknames to all the NN people, print Yes; otherwise, print No.

Sample Input 1

3
tanaka taro
tanaka jiro
suzuki hanako

Sample Output 1

Yes

The following assignment satisfies the conditions of nicknames described in the Problem Statement: a1=a_1 = taro, a2=a_2 = jiro, a3=a_3 = hanako. (a3a_3 may be suzuki, too.)
However, note that we cannot let a1=a_1 = tanaka, which violates the second condition of nicknames, since Person 22's family name s2s_2 is tanaka too.

Sample Input 2

3
aaa bbb
xxx aaa
bbb yyy

Sample Output 2

No

There is no way to give nicknames satisfying the conditions in the Problem Statement.

Sample Input 3

2
tanaka taro
tanaka taro

Sample Output 3

No

There may be a pair of people with the same family name and the same given name.

Sample Input 4

3
takahashi chokudai
aoki kensho
snu ke

Sample Output 4

Yes

We can let a1=a_1 = chokudai, a2=a_2 = kensho, and a3=a_3 = ke.

update @ 2024/3/10 10:35:21