提交时间:2023-02-02 14:25:49

运行 ID: 68095

#include<bits/stdc++.h> using namespace std; int n,m,a,b; char c; int p[10010]; int find(int x){ while(p[x]!=x){ int par=p[x]; p[x]=p[p[x]]; x=par; } return x; } int hebing(int a,int b){ int x=find(a),y=find(b); if(x!=y){ p[x]=y; return 0; }else{ return 1; } } int main(){ while(cin>>n>>m&&n!=0&&m!=0){ for(int i=0;i<n;i++){ p[i]=i; } for(int i=0;i<m;i++){ cin>>a>>b; if(hebing(a,b)){ cout<<"No"<<endl; break; } } int head=find(1),flag=0; for(int i=2;i<=n;i++){ if(find(i)!=head){ flag=1; cout<<"No"<<endl; break; } } if(flag==0) cout<<"Yes"<<endl; } return 0; }