#abc247b. B - Unique Nicknames
B - Unique Nicknames
Score : points
问题描述
有 名编号为 Person 、Person 、 和 Person 的人。其中,编号为 的人拥有一个姓氏 和一个名字 。
考虑为这 名人每人分配一个昵称。对于编号为 的人,其昵称 应满足以下所有条件:
- 必须与该人的姓氏或名字相同,即 或/和 成立。
- 不得与任何其他人的姓氏和名字相同。换句话说,对于所有满足 且 的整数 ,都有 以及 成立。
是否可能为所有 名人分配昵称?如果可以,则输出 Yes
;否则,输出 No
。
以上为通义千问 qwen-max 翻译,仅供参考。
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
.
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: 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.
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 chokudai
, kensho
, and ke
.
update @ 2024/3/10 10:35:21