// yukicoder: No.408 五輪ピック // 2019.8.2 bal4u #include #include #include #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } // 数値のハッシュ関数 #define HASHSIZ 1000003 int hash[HASHSIZ+5], *hashend = hash+HASHSIZ; int lookup(int a, int b) { int t, *p; t = (a << 15) | b; p = hash + t % HASHSIZ; while (*p) { if (*p == t) return 1; if (++p == hashend) p = hash; } return 0; } void insert(int a, int b) { int t, *p; t = (a << 15) | b; p = hash + t % HASHSIZ; while (*p) { if (*p == t) return; if (++p == hashend) p = hash; } *p = t; } typedef struct { int n, t; } Q; Q q[2000004]; int top, end; int N, M; int hi[20004], *to[20004]; char dis[20004]; int check(int a, int b) { int i, j, c, d; for (i = 0; i < hi[a]; i++) { c = to[a][i]; if (c != b && (dis[c] & 1)) { for (j = 0; j < hi[b]; j++) { d = to[b][j]; if (d != a && d != c && (dis[d] & 1)) { return 1; } } } } return 0; } int main() { int i, j, a, b, c, t; int *memo, sz; N = in(), M = in(); memo = malloc(M*2*sizeof(int)); sz = 0; for (i = 0; i < M; i++) { a = in(), b = in(); if (a > b) t = a, a = b, b = t; insert(a, b); memo[sz++] = a, memo[sz++] = b; hi[a]++; if (a > 1) hi[b]++; } for (i = 1; i <= N; i++) if (hi[i]) to[i] = malloc(sizeof(int)*hi[i]); memset(hi, 0, sizeof(int)*(N+1)); i = 0; while (i < sz) { a = memo[i++], b = memo[i++]; to[a][hi[a]++] = b; if (a > 1) to[b][hi[b]++] = a; } for (i = 0; i < hi[1]; i++) { a = to[1][i]; if (hi[a] == 1) { b = to[a][0]; if (hi[b] == 1) { hi[a] = hi[b] = 0; continue; } } else if (hi[a] == 2) { b = to[a][0], c = to[a][1]; if (hi[b] == 1 && hi[c] == 1) { hi[a] = hi[b] = hi[c] = 0; continue; } } q[end].n = a, q[end++].t = 1, dis[a] = 1; } while (top != end) { a = q[top].n, t = q[top++].t; if (t >= 2) continue; t++; for (i = 0; i < hi[a]; i++) { b = to[a][i]; if ((dis[b] & t) != t) { dis[b] |= t, q[end].n = b, q[end++].t = t; } } } for (a = 2; a <= N; a++) if (dis[a] & 2) { for (b = a+1; b <= N; b++) if (dis[b] & 2) { if (lookup(a, b) && check(a, b)) { puts("YES"); return 0; } } } puts("NO"); return 0; }