很经典的板子题
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M;
cin >> N >> M;
vector<vector<int>> E(N);
for (int i = 0; i < M; i++){
int u, v;
cin >> u >> v;
u--;
v--;
E[u].push_back(v);
E[v].push_back(u);
}
vector<bool> used(N, false);
bool ok = true;
for (int i = 0; i < N; i++){
if (!used[i]){
used[i] = true;
queue<int> Q;
Q.push(i);
int cv = 0, ce = 0;
while (!Q.empty()){
int v = Q.front();
Q.pop();
cv++;
for (int w : E[v]){
ce++;
if (!used[w]){
used[w] = true;
Q.push(w);
}
}
}
ce /= 2;
if (cv != ce){
ok = false;
}
}
}
if (ok){
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}