Pagini recente » Cod sursa (job #2289217) | Cod sursa (job #3244235) | Cod sursa (job #1658718) | Cod sursa (job #2282948) | Cod sursa (job #2487604)
#include <bits/stdc++.h>
#define NMAX 100001
using namespace std;
vector<int> graph[NMAX];
bitset<NMAX> seen;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
void dfs(int i)
{
seen[i] = 1;
for(auto x: graph[i]) if(!seen[x]) dfs(x);
}
int main()
{
int n, m;
fin >> n >> m;
while(m--)
{
int x, y;
fin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
int count = 0;
for(int i = 1; i <= n; i++) if(!seen[i])
{
dfs(i);
count++;
}
fout << count;
fin.close();
fout.close();
return 0;
}