Pagini recente » Cod sursa (job #3255827) | Cod sursa (job #63517) | Cod sursa (job #2506484) | Cod sursa (job #9128) | Cod sursa (job #1418871)
#include <fstream>
#define nmax 100050
#include <vector>
using namespace std;
ifstream f("dfs.in");
ofstream g("dfs.out");
bool v[nmax];
int N, M, compCon;
vector <int> a[nmax];
void del(int x){
v[x] = true;
for(auto j : a[x]){
if(! v[a[x][j]]){
del(a[x][j]);
}
}
}
int main()
{int x, y, i;
f>>N>>M;
for(i = 1; i <= M; ++i){
f>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
for(i = 1; i <= N; ++i){
if(!v[i]){
++compCon;
del(i);
}
}
g<<compCon<<'\n';
return 0;
}