/* -*- coding: utf-8 -*- * * 583.cc: No.583 鉄道同好会 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 500; /* typedef */ struct UFT { int links[MAX_N], ranks[MAX_N], sizes[MAX_N]; UFT() {} void clear(int n) { for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1; } int root(int i) { int i0 = i; while (links[i0] != i0) i0 = links[i0]; return (links[i] = i0); } int rank(int i) { return ranks[root(i)]; } int size(int i) { return sizes[root(i)]; } bool same(int i, int j) { return root(i) == root(j); } int merge(int i0, int i1) { int r0 = root(i0), r1 = root(i1), mr; if (r0 == r1) return r0; if (ranks[r0] == ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; ranks[r0]++; mr = r0; } else if (ranks[r0] > ranks[r1]) { links[r1] = r0; sizes[r0] += sizes[r1]; mr = r0; } else { links[r0] = r1; sizes[r1] += sizes[r0]; mr = r1; } return mr; } }; /* global variables */ UFT uft; int ges[MAX_N]; bool used[MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); uft.clear(n); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); ges[u]++, ges[v]++; used[u] = used[v] = true; uft.merge(u, v); } int on = 0; for (int i = 0; i < n; i++) if (ges[i] & 1) on++; if (on > 2) { puts("NO"); return 0; } int r = -1; for (int i = 0; i < n; i++) if (used[i]) { int ri = uft.root(i); if (r >= 0 && r != ri) { puts("NO"); return 0; } r = ri; } puts("YES"); return 0; }