import
java.util.*;
public
class
Main
{
static
String checkMirrorTree(
int
N,
int
M,
int
[][] A,
int
[][] B)
{
HashMap<Integer, Vector<Integer>> T1 =
new
HashMap<Integer, Vector<Integer>>();
HashMap<Integer, Vector<Integer>> T2 =
new
HashMap<Integer, Vector<Integer>>();
Set<Integer> st =
new
HashSet<Integer>();
for
(
int
i =
0
; i < M; i++) {
if
(T1.containsKey(A[i][
0
]))
{
T1.get(A[i][
0
]).add(A[i][
1
]);
}
else
{
T1.put(A[i][
0
],
new
Vector<Integer>());
T1.get(A[i][
0
]).add(A[i][
1
]);
}
st.add(A[i][
0
]);
st.add(A[i][
1
]);
}
for
(
int
i = M -
1
; i >=
0
; i--) {
if
(T2.containsKey(B[i][
0
]))
{
T2.get(B[i][
0
]).add(B[i][
1
]);
}
else
{
T2.put(B[i][
0
],
new
Vector<Integer>());
T2.get(B[i][
0
]).add(B[i][
1
]);
}
st.add(B[i][
0
]);
st.add(B[i][
1
]);
}
for
(
int
node : st) {
if
(!(T1.get(node) == T2.get(node)))
return
"Yes"
;
}
return
"No"
;
}
public
static
void
main(String[] args) {
int
N =
6
;
int
M =
5
;
int
[][] A = {
{
1
,
5
}, {
1
,
4
}, {
5
,
7
}, {
5
,
8
}, {
4
,
9
}
};
int
[][] B = {
{
1
,
4
}, {
1
,
5
}, {
4
,
9
}, {
5
,
8
}, {
5
,
7
}
};
System.out.print(checkMirrorTree(N, M, A, B));
}
}