//并查集没什么好说的 #include<iostream> #include<set> using namespace std; int father[1001]; void initialUnion() { for (int i = 0; i < 1001; i++) { father[i] = i; } } int findFather(int x) { if (x == father[x]) return x; else { father[x] = findFather(father[x]); return father[x]; } } void unionFather(int x, int y) { int x_father = findFather(x); int y_father = findFather(y); father[y_father] = father[x_father]; } int main() { int N, M; while (scanf("%d %d",&N,&M)!=EOF) { if (N == 0 && M == 0) { break; } initialUnion(); for(int i=0;i<M;i++) { int x, y; scanf("%d %d", &x, &y); unionFather(x, y); } set<int>blocks; for (int i = 1; i <= N; i++) { blocks.insert(findFather(i)); } if (blocks.size() == 1) { cout << "YES" << endl; } else { cout << "NO" << endl; } } }