#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class RollingHash { private: static const int X[], Y[], M[]; long long hash[3]; public: RollingHash(){ for(int i=0; i<3; ++i) hash[i] = 0; } void push_back(int a){ for(int i=0; i<3; ++i){ hash[i] *= X[i]; hash[i] += a; hash[i] %= M[i]; } } bool operator==(const RollingHash& rh) const{ for(int i=0; i<3; ++i){ if(hash[i] != rh.hash[i]) return false; } return true; } bool operator!=(const RollingHash& rh) const{ return !(*this == rh); } }; const int RollingHash::X[] = {1685440109, 1389328937, 1813126193}; // 素数 const int RollingHash::Y[] = {1835226359, 1406652555, 643336582}; // X * Y == 1 (mod M) const int RollingHash::M[] = {2000000087, 2000000089, 2000000099}; // 合同式の法(素数) int main() { int n, m; cin >> n >> m; vector a(m), b(m); vector > edges(n); for(int i=0; i> a[i] >> b[i]; -- a[i]; -- b[i]; edges[a[i]].push_back(b[i]); edges[b[i]].push_back(a[i]); } vector > s(n); for(int x : edges[0]){ for(int y : edges[x]){ s[y].insert(x); } } for(int i=0; i{ b[i] } || s[b[i]] == set{ a[i] }) continue; cout << "YES" << endl; return 0; } cout << "NO" << endl; return 0; }