# 宣传部肖同学

``````4 5
1 2
2 3
1 3
3 2
1 2
``````

``3``

``````#include<iostream>
using namespace std;
int h[501];
int find(int i){
if(h[i]!=i)
return find(h[i]);
return i;
}
int main(){
int  a,b,n,m,all=0;
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++)
h[i]=i;
for(int i=1;i<=m;i++)
{
scanf("%d %d",&a,&b);
int ta=find(a);
int tb=find(b);
if(ta!=tb)
h[tb]=ta;
}
for(int i=1;i<=n;i++)
{
if(find(i)==find(1))
all++;
}
cout<<all;
}``````

``````#include <bits/stdc++.h>
#define IO                       \
ios::sync_with_stdio(false); \
cin.tie(0);                  \
cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

struct node {
int from;
int to;
int next;
int cost;
} edge[maxn << 1];

void init() {
tot = 0;
}

void addedge(int u, int v, int cost) {
edge[tot].from = u;
edge[tot].to = v;
edge[tot].cost = cost;
}
int n, m;

bool vis[maxn];

void dfs(int x, int fa) {
if (vis[x])
return;
vis[x] = true;
for (int i = head[x]; i != -1; i = edge[i].next) {
int to = edge[i].to;
if (to == fa)
continue;
dfs(to, x);
}
}
void solve() {
mem(vis, 0);
dfs(1, -1);
int ans = 0;
for (int i = 1; i <= n; i++) {
if (vis[i])
++ans;
}
cout << ans << endl;
}
int main() {
#ifdef LOCAL_IM0QIANQIAN
freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
IO;
#endif // LOCAL_IM0QIANQIAN

init();
cin >> n >> m;
assert(n <= 500);
assert(n >= 2);
assert(m >= 1);
assert(m <= 500);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;