#abc232c. C - Graph Isomorphism
C - Graph Isomorphism
Score : points
问题描述
高桥和青木各自拥有一个由 根绳索连接 个球的玩具。
在高桥的玩具中,球被编号为 ,第 根绳索将球 和 连接在一起。
类似地,在青木的玩具中,球也被编号为 ,第 根绳索将球 和 连接在一起。
在每个玩具中,没有绳索会将一个球与自身相连,也没有两个球会被两条或更多的不同绳索相连。
Snuke 正在思考这两个玩具是否具有相同的形状。
这里,若满足以下条件,则认为它们具有相同的形状:
- 序列 是 的一个排列。
- 对于每一对整数 在 到 (包括两端点)之间,满足以下条件:
- 高桥玩具中的球 和 若由一根绳索相连,则青木玩具中的球 和 也必须由一根绳索相连。
如果两个玩具具有相同的形状,则输出 Yes
;否则,输出 No
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi and Aoki each have a toy made by attaching cords to balls.
In Takahashi's toy, the balls are numbered , and the -th cord ties Ball and .
Similarly, in Aoki's toy, the balls are numbered , and the -th cord ties Ball and .
In each toy, no cord ties a ball to itself, and no two balls are tied by two or more different cords.
Snuke is wondering whether the two toys have the same shape.
Here, they are said to have the same shape when there is a sequence that satisfies the conditions below.
- is a permutation of .
- For every pair of integers between and (inclusive), the following holds.
- Balls and in Takahashi's toy are tied by a cord if and only if Balls and in Aoki's toy are tied by a cord.
If the two toys have the same shape, print Yes
; otherwise, print No
.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the two toys have the same shape, print Yes
; otherwise, print No
.
Sample Input 1
4 4
1 2
1 3
1 4
3 4
1 3
1 4
2 3
3 4
Sample Output 1
Yes
Takahashi's toy is illustrated on the left in the figure below, and Aoki's is illustrated on the right.
The following figure shows that the two toys have the same shape. The condition in the statement is satisfied when , for example.
Sample Input 2
5 6
1 2
1 3
1 4
3 4
3 5
4 5
1 2
1 3
1 4
1 5
3 5
4 5
Sample Output 2
No
The two toys do not have the same shape.
Sample Input 3
8 0
Sample Output 3
Yes
update @ 2024/3/10 10:06:31