#include #include #include #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) using namespace std; int main() { // input int n, m; cin >> n >> m; vector a(m), b(m); repeat (i,m) { cin >> a[i] >> b[i]; -- a[i]; -- b[i]; } // make graph const int root = 0; vector > g(n); repeat (i,m) { g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } // select vertices set d1; for (int i : g[root]) d1.insert(i); vector > g1(n); repeat (i,n) for (int j : g[i]) if (d1.count(j)) g1[i].insert(j); // find cycle bool ans = false; repeat (e,m) { int i = a[e]; int j = b[e]; bool g1_i_count_j = g1[i].count(j); g1[i].erase(j); bool g1_j_count_i = g1[j].count(i); g1[j].erase(i); if (not g1[i].empty() and not g1[j].empty()) { if (not (g1[i].size() == 1 and g1[j].size() == 1 and g1[i] == g1[j])) { ans = true; } } if (g1_i_count_j) g1[i].insert(j); if (g1_j_count_i) g1[j].insert(i); if (ans) goto done; } done: // output cout << (ans ? "YES" : "NO") << endl; return 0; }