/**
判断无向图是否连通 → 并查集
*/#include<bits/stdc++.h>usingnamespace std;#define N 1000000int tree[N];intfindRoot(int x){if(tree[x]==-1)return x;elsereturn tree[x]=findRoot(tree[x]);}intmain(){int n, m;int u, v;scanf("%d %d",&n,&m);//n个点m个输入fill(tree, tree+n+1,-1);//初始化tree数组0到n+1下标的值为-1while(m--){scanf("%d %d",&u,&v);
u =findRoot(u);
v =findRoot(v);if( u != v )//这两个点是否在同一个集合里
tree[u]= v;//不在集合里就放进去}int ans =0;for(int i =1; i <= n; i++){if(tree[i]==-1)
ans++;}//只有一个根节点即为连通if(ans ==1)printf("yes\n");elseprintf("no\n");return0;}