Pagini recente » Cod sursa (job #2414753) | Rating Albu Virgil (tarzanRo) | Cod sursa (job #2200793) | Cod sursa (job #1806661) | Cod sursa (job #1805915)
#include <bits/stdc++.h>
using namespace std;
vector <int> a[100001];
int f[100001];
int functie(int x){
f[x] = 1;
for (int i = 0; i < a[x].size(); i++)
if (f[a[x][i]] == 0)
functie(a[x][i]);
}
int main() {
int n, m ,i;
ifstream fin ("dfs.in");
ofstream fout ("dfs.out");
fin >> n >> m;
for (i = 1; i <= m; i++){
int x, y;
fin >> x >> y;
a[x].push_back(y);
a[y].push_back(x);
}
int rasp = 0;
for (i = 1; i <= n; i++)
if (f[i] == 0){
functie(i);
rasp ++;
}
fout << rasp;
return 0;
}