#abc285d. D - Change Usernames
D - Change Usernames
Score : points
问题描述
你运营一个拥有 个用户的网络服务。
第 个用户当前的用户名为 ,希望将其更改为 。这里, 是两两不同的,同样地, 也是两两不同的。
确定是否存在一个合适的顺序来更改他们的用户名,以满足所有请求,同时遵守以下条件:
- 你每次只能更改一个用户的用户名;
- 每个用户的用户名只能更改一次;
- 更改用户名时,新的用户名在那时不应被其他用户使用。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You run a web service with users.
The -th user with a current handle wants to change it to .
Here, , and are pairwise distinct, and so are , and .
Determine if there is an appropriate order to change their handles to fulfill all of their requests subject to the following conditions:
- you change only one user's handle at a time;
- you change each user's handle only once;
- when changing the handle, the new handle should not be used by other users at that point.
Constraints
- and are strings of length between and (inclusive) consisting of lowercase English letters.
- are pairwise distinct.
- are pairwise distinct.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if they can change their handles to fulfill all of their requests subject to the conditions; print No
otherwise.
Sample Input 1
2
b m
m d
Sample Output 1
Yes
The -st user with a current handle b
wants to change it to m
.
The -nd user with a current handle m
wants to change it to d
.
First, you change the -nd user's handle from m
to d
; then you change the -st user's handle from b
to m
. This way, you can achieve the objective.
Note that you cannot change the -st user's handle to m
at first, because it is used by the -nd user at that point.
Sample Input 2
3
a b
b c
c a
Sample Output 2
No
The -st user with a current handle a
wants to change it to b
.
The -nd user with a current handle b
wants to change it to c
.
The -rd user with a current handle c
wants to change it to a
.
We cannot change their handles subject to the conditions.
Sample Input 3
5
aaa bbb
yyy zzz
ccc ddd
xxx yyy
bbb ccc
Sample Output 3
Yes
update @ 2024/3/10 11:55:40