Pagini recente » Cod sursa (job #2046587) | Cod sursa (job #1364887) | Cod sursa (job #1607757) | Cod sursa (job #374496) | Cod sursa (job #2039299)
#include <fstream>
#include <vector>
using namespace std;
/*ifstream cin ("input");
ofstream cout ("output");*/
ifstream cin ("dfs.in");
ofstream cout ("dfs.out");
vector < vector < int > > gr (100100);
vector < int > used (100100);
void dfs (int root){
for (auto &x : gr[root]){
if (!used[x]){
used[x] = true;
dfs(x);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int nodes , edges;
cin>>nodes>>edges;
for (int i=1; i<=edges; i++){
int a , b;
cin>>a>>b;
gr[a].push_back(b);
gr[b].push_back(a);
}
int cont = 0;
for (int i=1; i<=nodes; i++){
if (!used[i]){
cont ++;
used[i] = true;
dfs(i);
}
}
cout<<cont;
return 0;
}