fn.cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
using namespace std;
bool visited[10000];
bool findBunny(vector<vector<int> > & gr, int start){
stack<int> s, depth;
int paws = 0, maxDepth = 0;
s.push(start);
depth.push(0);
while(!s.empty()){
int n = s.top(), d = depth.top();
s.pop();
visited[n] = true;
bool leaf = true;
if(d > maxDepth) maxDepth = d;
//printf("node %d: ", n);
for(unsigned i = 0; i < gr[n].size(); i++){
if(!visited[gr[n][i]]){
//printf("%d, ", gr[n][i]);
s.push(gr[n][i]);
depth.push(d + 1);
leaf = false;
}
}
//printf("\n");
if(leaf){
paws++;
}
}
if(maxDepth >= 2){
paws++;
}
//printf("paws: %d\n", paws);
return paws > 3;
}
void solve(int n, int m){
vector<vector<int> > gr(n + 1);
int a, b;
memset(visited, 0, 10000 * sizeof(bool));
for(int i = 0; i < m; i++){
scanf("%d %d ", &a, &b);
gr[a].push_back(b);
gr[b].push_back(a);
}
for(int i = 1; i <= n; i++){
if(!visited[i]){
if(findBunny(gr, i)){
printf("YES\n");
return;
}
}
}
printf("NO\n");
}
int main(){
int n, m;
while(scanf("%d %d ", &n, &m) == 2){
solve(n, m);
}
return 0;
}