Pagini recente » Cod sursa (job #625235) | Cod sursa (job #1035021) | Cod sursa (job #865973) | Cod sursa (job #1482188) | Cod sursa (job #1112602)
#include<cstdio>
#include<vector>
#define pb push_back
#define N_MAX 100010
using namespace std;
vector <int> G[N_MAX];
bool use[N_MAX];
int N,Sol=0;
inline void DFS(int Nod)
{
use[Nod]=true;
for (vector <int> :: iterator it=G[Nod].begin();it!=G[Nod].end();++it)
if (!use[*it]) DFS(*it);
}
inline void Load_Data(int &N)
{
int M,x,y;
scanf("%d%d",&N,&M);
for (int i=1;i<=M;++i) {scanf("%d%d",&x,&y); G[x].pb(y); G[y].pb(x);}
for (int i=1;i<=N;++i) use[i]=false;
}
int main()
{
freopen("dfs.in","r",stdin);
freopen("dfs.out","w",stdout);
Load_Data(N);
for (int i=1;i<=N;++i)
if (!use[i]) {Sol++; DFS(i);}
printf("%d\n",Sol);
fclose(stdin); fclose(stdout);
return 0;
}