Pagini recente » Cod sursa (job #3298488) | Rating Zabolai Zsolt (zsee) | Cod sursa (job #214767) | Statisticile problemei Operatie | Cod sursa (job #3300016)
#include <fstream>
#include <vector>
using namespace std;
const int N = 1e5;
vector <int> a[N+1] ; // liste de adiacenta
int nr = 0;
bool viz[N+1];
void dfs(int x)
{
viz[x]=true;
for(auto y:a[x])
{
if(!viz[y])
dfs(y);
}
}
int main()
{
ifstream in("dfs.in");
ofstream out("dfs.out");
int n;
long long m;
in>>n>>m;
int x,y;
while(in>>x>>y)
{
a[x].push_back(y);
a[y].push_back(x);
}
for(int i = 1 ; i <= n ;i++)
{
if(!viz[i])
{
nr++;
dfs(i);
}
}
out<<nr;
in.close();
out.close();
return 0;
}