Baltic Olympiad in Informatics: 2011 Day 2, Problem 4
Let
Write a program that determines if an arbitrary undirected connected graph is a tree-mirrored graph.
Constraints
Subtask 1 [30%]
Subtask 2 [30%]
Subtask 3 [40%]
No additional constraints.
Input Specification
The first line of input contains two space-separated integers
The vertices in
Output Specification
The first and only line of output should contain the string YES
if the graph NO
otherwise.
Sample Input 1
7 7
1 2
2 3
3 4
4 5
5 6
6 7
7 1
Sample Output 1
NO
Sample Input 2
6 6
1 2
2 3
2 4
3 5
4 5
5 6
Sample Output 2
YES
Sample Input 3
22 28
13 8
8 1
1 22
1 12
1 14
13 18
13 4
4 20
20 7
13 15
15 3
15 9
9 16
9 19
22 5
12 5
14 5
5 11
11 6
18 6
7 10
10 17
17 6
3 21
21 6
16 2
19 2
2 21
Sample Output 3
YES
Explanation for Sample 3
The last example input corresponds to the graph in Figure 1.
Comments