Pagini recente » Cod sursa (job #2083763) | Istoria paginii runda/o-n_logan/clasament | Cod sursa (job #449238) | Istoria paginii runda/o-n_logan/clasament | Cod sursa (job #2350248)
#include <bits/stdc++.h>
#define NMAX 100100
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
void citire();
void DFS(int x);
vector <int> G[NMAX];
bool uz[NMAX];
int n, m, c;
int main(){
int i;
citire();
for(i=1;i<=n;i++)
if(!uz[i]){
c++;
DFS(i);
}
fout << c;
}
void citire(){
int i, x, y;
fin >> n >> m;
for(i=0;i<m;i++){
fin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void DFS(int x){
int i;
uz[x] = 1;
for(i=0;i<G[x].size();i++)
if(!uz[G[x][i]]) DFS(G[x][i]);
}