Pagini recente » Borderou de evaluare (job #3251330) | Administrare | Cod sursa (job #3206011) | Cod sursa (job #1960497) | Cod sursa (job #3269910)
# include <fstream>
# include <vector>
# define Nmax 100002
using namespace std;
ifstream f("dfs.in"); ofstream g("dfs.out");
vector <int> L[Nmax];
int n, m, x, y, nr , viz[Nmax];
void dfs(int p)
{ viz[p]=1;
///vector <int> :: iterator it=L[p].begin(), sf=L[p].end();
/// for(; it != sf ; ++it)
/// if(!viz[*it]) dfs(*it);
for(int j=0;j<L[p].size();j++)
{ int vec=L[p][j];
if(viz[vec]==0) dfs(vec);
}
}
int main()
{
f>>n>>m;
for(int i = 1; i <= m; ++i)
{f>>x>>y; L[x].push_back(y); L[y].push_back(x);}
for(int i=1; i<=n; ++i )
if(viz[i]==0)
{ nr++;
dfs(i);
}
g<<nr<<'\n'; g.close();
return 0;
}