#include #define rep(i,n) for(int i=0;i G[2 * 10000]; int A, B; //i:辺をたどった回数, j:今いる頂点, checked:通った頂点の集合 bool rec(int i, int j, set checked) { /* printf("rec(%d, %d, set)\n", i, j); set::iterator it = checked.begin(); while (it != checked.end()) { cout << *it << ", " << endl; it++; } */ if (i == 5) { if (j == 0) return true; else return false; } if (j != 0) { checked.insert(j); } bool ret = false; rep(ii,G[j].size()) { if (checked.find(G[j][ii]) == checked.end()) { //次の頂点がまだ未探索の場合 //checked.insert(G[j][i]); ret = ret || rec(i + 1, G[j][ii], checked); //checked.erase(G[j][i]); } } return ret; } signed main() { cin >> N >> M; rep(i,M) { cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } set checked; if (rec(0, 0, checked)) { cout << "YES" << endl; } else { cout << "NO" << endl; } }