Pagini recente » Statistici Confucius Bot (Confucius) | Cod sursa (job #2667316)
#include <fstream>
#include <vector>
#define N 100005
using namespace std;
ifstream fin("bfs.in");
ofstream fout("bfs.out");
vector <int> muchii[N];
int n, m, viz[N], ct;
void Citire()
{
int i,x,y;
fin >> n >> m;
for (i = 1; i <= m; i++)
{
fin >> x >> y;
muchii[x].push_back(y);
muchii[y].push_back(x);
}
}
void DFS(int x)
{
int i;
viz[x] = 1;
for (auto i : muchii[x])
if (viz[i] == 0)
DFS(i);
}
void Rezolvare()
{
int i;
for (i = 1; i <= n; i++)
{
if (viz[i] == 0)
{
ct++;
DFS(i);
}
}
fout << ct;
}
int main()
{
Citire();
Rezolvare();
return 0;
}