No.3196 Unique Nickname
Problem Statement
There are $N$ participants, and the $i$-th participant ($1\leq i\leq N$) is given a family name $S_i$ and a given name $T_i$.
A participant $i$ can use as a nickname only those of their family name $S_i$ or given name $T_i$ that do not coincide with the family name or given name of any other participant.
Determine whether each of the $N$ participants has $1$ or more available nicknames.
Input
$N$ $S_1\ T_1$ $S_2\ T_2$ $\dots$ $S_N\ T_N$
- $1\leq N\leq 100$
- $S_i,T_i$ are strings consisting only of lowercase English letters
- $1\leq |S_i|,|T_i|\leq 15$
- If $i\neq j$, then $(S_i,T_i)\neq (S_j,T_j)$
- For each individual, $S_i\neq T_i$
Output
Print Yes if everyone has 1 or more available nicknames, and No if there is even one person who does not.
Print a newline at the end.
Sample
Sample 1
Input
3 tanaka taro sato hanako tanaka jiro
Output
Yes
- Person $1$ (
tanaka taro):tanakacannot be used because it coincides with the family name of person $3$. However,tarocan be used because it does not coincide with anyone's name. → OK - Person $2$ (
sato hanako): Neithersatonorhanakocoincides with anyone's name. → OK - Person $3$ (
tanaka jiro):tanakacannot be used because it coincides with the family name of person $1$. However,jirocan be used because it does not coincide with anyone's name. → OK
Yes.
Sample 2
Input
3 saito ichiro saito jiro suzuki ichiro
Output
No
Person $1$ (saito ichiro): saito coincides with the family name of person $2$, and ichiro coincides with the given name of person $3$. This person does not have any available nickname ($1$ or more are required).
Therefore, the answer is No.
Sample 3
Input
2 suzuki sato sato suzuki
Output
No
Person $1$ (suzuki sato): suzuki coincides with the given name of person $2$, and sato coincides with the family name of person $2$. There is no available nickname.
Therefore, the answer is No.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nauclhlt