Pagini recente » Borderou de evaluare (job #804586) | Rating popa eliana (elianap) | Cod sursa (job #2717703) | Cod sursa (job #2740727) | Cod sursa (job #3252604)
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
ifstream f("dfs.in");
ofstream g("dfs.out");
int n,m,componente;
vector<int> v[N];
bitset<N> viz;
void DFS(int nod)
{
viz[nod]=1;
for(auto vec:v[nod])
if(!viz[vec])
DFS(vec);
}
int main()
{
f>>n>>m;
for(int i=1; i<=m; i++)
{
int x,y;
f>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
/// TOTUSI VOI FOLOSI BFS
for(int i=1; i<=n; i++)
if(!viz[i])
{
componente++;
DFS(i);
}
g<<componente;
return 0;
}