#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAX_MOD 1000000007 #define REP(i,n) for(int i = 0;i < n;++i) vector path[30000]; int have_come[10][30000] = {}; int main() { int n, m; cin >> n >> m; REP(i, m) { int a, b; cin >> a >> b; path[a].push_back(b); path[b].push_back(a); } queue> hoge; hoge.push(make_tuple(1,1,0)); while (hoge.empty() == false) { int now_here = get<0>(hoge.front()); int before_come = get<1>(hoge.front()); int score = get<2>(hoge.front()); hoge.pop(); if (score > 5) {//5を超えちゃった場合 cout << "NO" << endl; return 0; } for (int i = 0;i < path[now_here].size();++i) { if (path[now_here][i] != before_come) { if (have_come[score+1][path[now_here][i]] == 0) { if (have_come[4 - score][path[now_here][i]] == 1) { cout << "YES" << endl; return 0; } have_come[score+1][path[now_here][i]] = true; hoge.push(make_tuple(path[now_here][i], now_here, score + 1)); } } } } //そもそも道すらなかった場合 cout << "NO" << endl; return 0; }