102471: [AtCoder]ABC247 B - Unique Nicknames

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

There are $N$ people numbered Person $1$, Person $2$, $\dots$, and Person $N$. Person $i$ has a family name $s_i$ and a given name $t_i$.

Consider giving a nickname to each of the $N$ people. Person $i$'s nickname $a_i$ should satisfy all the conditions below.

  • $a_i$ coincides with Person $i$'s family name or given name. In other words, $a_i = s_i$ and/or $a_i = t_i$ holds.
  • $a_i$ does not coincide with the family name and the given name of any other person. In other words, for all integer $j$ such that $1 \leq j \leq N$ and $i \neq j$, it holds that $a_i \neq s_j$ and $a_i \neq t_j$.

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

Constraints

  • $2 \leq N \leq 100$
  • $N$ is an integer.
  • $s_i$ and $t_i$ are strings of lengths between $1$ and $10$ (inclusive) consisting of lowercase English alphabets.

Input

Input is given from Standard Input in the following format:

$N$
$s_1$ $t_1$
$s_2$ $t_2$
$\vdots$
$s_N$ $t_N$

Output

If it is possible to give nicknames to all the $N$ 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: $a_1 =$ taro, $a_2 =$ jiro, $a_3 =$ hanako. ($a_3$ may be suzuki, too.)
However, note that we cannot let $a_1 =$ tanaka, which violates the second condition of nicknames, since Person $2$'s family name $s_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 $a_1 =$ chokudai, $a_2 =$ kensho, and $a_3 =$ ke.

Input

题意翻译

给定 $ n $ 个人的姓和名,定义一个人的昵称为他的姓或名,且一个人的昵称不能与其他人的姓或名重复,判断给定的数据是否能为每个人钦定一个昵称。可行输出 `Yes`,反之输出 `No`。

Output

分数:200分

问题描述

有编号为Person $1$,Person $2$,$\dots$,Person $N$的$N$个人。Person $i$有姓$s_i$和名$t_i$。

考虑给这$N$个人起昵称。Person $i$的昵称$a_i$应满足以下所有条件。

  • $a_i$与Person $i$的姓或名相同。换句话说,$a_i = s_i$和/或$a_i = t_i$成立。
  • $a_i$不与任何其他人的姓和名相同。换句话说,对于所有整数$j$,满足$1 \leq j \leq N$且$i \neq j$,有$a_i \neq s_j$和$a_i \neq t_j$。

是否可能给这$N$个人都起昵称?如果可能,输出Yes;否则,输出No

约束条件

  • $2 \leq N \leq 100$
  • $N$是整数。
  • $s_i$和$t_i$是长度在$1$到$10$(含)之间的由小写英文字母组成的字符串。

输入

从标准输入以以下格式获取输入:

$N$
$s_1$ $t_1$
$s_2$ $t_2$
$\vdots$
$s_N$ $t_N$

输出

如果可能给这$N$个人都起昵称,输出Yes;否则,输出No


样例输入1

3
tanaka taro
tanaka jiro
suzuki hanako

样例输出1

Yes

以下分配满足问题描述中的昵称条件:$a_1 =$ taro,$a_2 =$ jiro,$a_3 =$ hanako。但是,请注意我们不能让$a_1 =$ tanaka,因为它违反了昵称的第二个条件,因为Person $2$的姓$s_2$也是tanaka


样例输入2

3
aaa bbb
xxx aaa
bbb yyy

样例输出2

No

没有满足问题描述中的昵称条件的方法。


样例输入3

2
tanaka taro
tanaka taro

样例输出3

No

可能存在一组具有相同姓和相同名的人。


样例输入4

3
takahashi chokudai
aoki kensho
snu ke

样例输出4

Yes

我们可以让$a_1 =$ chokudai,$a_2 =$ kensho,$a_3 =$ ke

加入题单

上一题 下一题 算法标签: