Pagini recente » Cod sursa (job #1609130) | Cod sursa (job #2601768) | Cod sursa (job #921830) | Cod sursa (job #3162564) | Cod sursa (job #2758409)
#include <cstdio>
#include <vector>
using namespace std;
int n, m, nod[100005];
vector <int> g[100005];
inline void DFS(int j){
for(int i = 0; i < g[j].size() ; ++i)
if(nod[g[j][i]] == 0) nod[g[j][i]] = 1, DFS(g[j][i]);
}
int main()
{
freopen("dfs.in", "r", stdin);
freopen("dfs.out", "w", stdout);
scanf("%d%d", &n, &m);
int x, y;
for(int i = 1; i <= m ; ++i){
scanf("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
int conexe = 0;
for(int i = 1; i <= n ; ++i)
if(nod[i] == 0){nod[i] = 1; ++conexe; DFS(i);}
printf("%d", conexe);
return 0;
}