atcoder#ABC232C. [ABC232C] Graph Isomorphism
[ABC232C] Graph Isomorphism
Score : points
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
.
4 4
1 2
1 3
1 4
3 4
1 3
1 4
2 3
3 4
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.
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
No
The two toys do not have the same shape.
8 0
Yes