#include<iostream> #pragma GCC optimize(3) #define N 6000 #define endl '\n' usingnamespace std; int fi[N], root[N]; intfind(int x)//并查集搜索 { if (fi[x] != x) fi[x] = find(fi[x]); return fi[x]; } voidmerge(int x, int y)//合并根节点 { int a = find(x); int b = find(y); if (a != b) { root[b] += root[a]; fi[a] = b; } } intmain() { int n, m; while (cin >> n >> m) { for (int i = 1; i <= n; i++) { fi[i] = i; root[i] = 1; } for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; merge(x, y); } if (root[find(1)] == n) cout << "YES" << endl; else cout << "NO" << endl; }