Pagini recente » Profil Darius_C | Profil Darius_C | Diferente pentru problema/avd intre reviziile 5 si 4 | Diferente pentru utilizator/darius_c intre reviziile 33 si 38 | Cod sursa (job #544952)
Cod sursa(job #544952)
#include <vector>
#include <fstream>
#include <cstdlib>
#define N_MAX 100011
using namespace std;
bool was[N_MAX];
vector< int > G[N_MAX];
inline void DFS( int x )
{
was[x]=true;
vector< int >::const_iterator it=G[x].begin(), iend=G[x].end();
for( ; it < iend; ++it )
if( false == was[*it] )
DFS(*it);
}
int main( void )
{
int N, M, x, y;
ifstream in( "dfs.in" );
for( in>>N>>M; M; --M )
{
in>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
for( y=0, x=1; x <= N; ++x )
if( false == was[x] )
{
++y;
DFS(x);
}
ofstream out( "dfs.out" );
out<<y<<'\n';
return EXIT_SUCCESS;
}