#include #include #include #include using namespace std; int main() { int N, M; cin >> N >> M; vector graph[20050]; int A[50010] = { 0 }, B[50010] = { 0 }; for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; A[i] = a, B[i] = b; graph[a].push_back(b); graph[b].push_back(a); } /*for (int i = 0; i <= N; i++) { cout << i << " " ; for (int j = 0; j < graph[i].size(); j++) { cout << graph[i][j]<<" "; } cout << endl; } */ vector> p(N+1); for (int i = 0; i < graph[1].size(); i++) { int a = graph[1][i]; for (int j = 0; j < graph[a].size(); j++) { int b = graph[a][j]; if (b == 1) continue; p[b].insert(a); //cout << a << " " << b << endl; } } /* for (int i = 0; i < p.size(); i++) { for (int j = i; j < p.size(); j++) { if (i == j) continue; int a1 = p[i].first, b1 = p[i].second, a2 = p[j].first, b2 = p[j].second; if (a1 == a2 || b1 == b2 || a2 == b1 || a1 == b2) continue; bool flag = false; for (int j = 0; j < graph[b1].size(); j++) { if (graph[b1][j] == b2) flag = true; } if (flag) { // cout << a1 << " " << b1 << " " << a2 << " " << b2 << endl; cout << "YES" << endl; return 0; } } } */ for (int i = 0; i < M; i++) { int c = A[i], d = B[i]; for (int j = 0; j < graph[c].size(); j++) { if (d == graph[c][j]) { for (auto &s : p[c]) { for (auto &t : p[d]) { if (s != t) { cout << "YES" << endl; return 0; } } } } } } cout << "NO" << endl; return 0; }