Pagini recente » Cod sursa (job #2961751) | Cod sursa (job #3274713) | Cod sursa (job #2237622) | Cod sursa (job #1875657) | Cod sursa (job #3213472)
#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(int vecin: graph[k]){
if(visited[vecin]!=true){
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;
}