Pagini recente » Cod sursa (job #2136277) | Cod sursa (job #3262738) | Cod sursa (job #2098029) | Cod sursa (job #1832455) | Cod sursa (job #3213479)
#include<iostream>
#include<vector>
#include<fstream>
#include<stack>
#define SIZE 100005
std::ifstream fin("input.txt");
std::ofstream fout("output.txt");
bool visited[SIZE];
std::vector<int> graph[SIZE];
void DFS(int k){
visited[k] = true;
for(unsigned i =0; i< graph[k].size();i++){
int vecin = graph[k][i];
if(!visited[vecin]){
DFS(vecin);
}
}
}
int main(){
int N, M;
fin>>N>>M;
for(int i=0; i<M; i++){
int x, y;
fin>>x>>y;
graph[x].push_back(y);
graph[y].push_back(x);
}
DFS(1);
int nr = 0;
for(int i =0; i<N; i++){
nr += !visited[i];
}
fout<<nr;
fin.close();
fout.close();
return 0;
}