Pagini recente » Cod sursa (job #565499) | Cod sursa (job #575489) | Cod sursa (job #570512) | Cod sursa (job #916014) | Cod sursa (job #447356)
Cod sursa(job #447356)
/*
* File: main.cpp
* Author: virtualdemon
*
* Created on April 28, 2010, 3:22 PM
*/
#include <vector>
#include <cstdlib>
#include <fstream>
#define Nmax 100011
/*
*
*/
using namespace std;
bool uz[Nmax];
vector< int > G[Nmax];
inline void DFS( int x )
{
vector< int >::const_iterator it=G[x].begin(), iend=G[x].end();
uz[x]=true;
for( ; it < iend; ++it )
if( !uz[*it] )
DFS(*it);
}
int main(int argc, char** argv)
{
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( !uz[x] )
{
++y;
DFS(x);
}
ofstream out( "dfs.out" );
out<<y<<'\n';
return (EXIT_SUCCESS);
}