atcoder#ABC247B. [ABC247B] Unique Nicknames
[ABC247B] Unique Nicknames
Score : points
Problem Statement
There are people numbered Person , Person , , and Person . Person has a family name and a given name .
Consider giving a nickname to each of the people. Person 's nickname should satisfy all the conditions below.
- coincides with Person 's family name or given name. In other words, and/or holds.
- does not coincide with the family name and the given name of any other person. In other words, for all integer such that and , it holds that and .
Is it possible to give nicknames to all the people? If it is possible, print Yes
; otherwise, print No
.
Constraints
- is an integer.
- and are strings of lengths between and (inclusive) consisting of lowercase English alphabets.
Input
Input is given from Standard Input in the following format:
Output
If it is possible to give nicknames to all the people, print Yes
; otherwise, print No
.
3
tanaka taro
tanaka jiro
suzuki hanako
Yes
The following assignment satisfies the conditions of nicknames described in the Problem Statement: taro
, jiro
, hanako
. ( may be suzuki
, too.)
However, note that we cannot let tanaka
, which violates the second condition of nicknames, since Person 's family name is tanaka
too.
3
aaa bbb
xxx aaa
bbb yyy
No
There is no way to give nicknames satisfying the conditions in the Problem Statement.
2
tanaka taro
tanaka taro
No
There may be a pair of people with the same family name and the same given name.
3
takahashi chokudai
aoki kensho
snu ke
Yes
We can let chokudai
, kensho
, and ke
.