Theory of Six Degrees of Separation
The concept of six degrees of separation was introduced in 1969 by American psychologists Stanley Milgram and Jeffrey Travers. Their theory posits that any two individuals on Earth can be connected through a short chain of mutual acquaintances, typically involving five intermediaries. Consequently, if these two individuals were to exchange handshakes via their mutual acquaintances, it would take, on average, six handshakes.
For example, if person A knows person G through a sequence of people B, C, D, E, and F, the handshake chain would be: A ↔ B ↔ C ↔ D ↔ E ↔ F ↔ G. In this scenario, there are precisely six handshakes, and the chain of mutual acquaintances includes exactly 5 people (B, C, D, E, F).
In this task, you are not required to verify this hypothesis for the entire global population. Instead, you will be provided with a description of a specific group of people. Your task is to determine whether there exists a chain of mutual acquaintances, consisting of no more than 5 people, between any two members of the group.
Input
The input file describes a group of N people.
The first line contains two natural numbers N (2 ≤ N ≤ 100) and M (0 ≤ M ≤ N·(N-1)/2) — representing the number of people in the group and the number of pairs of acquaintances among them.
The following M lines each contain two natural numbers A and B (1 ≤ A, B ≤ N), separated by a space, indicating that these two individuals are acquaintances. All group members are numbered from 1 to N.
Output
In the output file, write YES if there is a chain of mutual acquaintances consisting of no more than 5 people between any two members of the group.
If there are at least two people for whom no such chain exists, write NO.