0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-05 02:26:26 +00:00
OI-codes/Luogu/P2097/P2097.cpp

35 lines
609 B
C++
Raw Normal View History

2020-10-19 14:25:55 +00:00
#include <bits/stdc++.h>
using namespace std;
vector<int> l[100010];
2021-11-19 09:01:13 +00:00
int n, m, f, s, ans, pd[100010];
2020-10-19 14:25:55 +00:00
void dfs(int x) {
for (int y = 0; y < l[x].size(); y++) {
if (!pd[l[x][y]]) {
pd[l[x][y]] = 1;
dfs(l[x][y]);
}
}
}
int main() {
int p, q;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> p >> q;
l[p].push_back(q);
l[q].push_back(p);
}
for (int i = 1; i <= n; i++) {
if (!pd[i]) {
ans++;
pd[i] = 1;
dfs(i);
}
}
cout << ans << endl;
return 0;
}