#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> adj[101];
int a, b;
int visited[101];
int cnt;
void dfs(int here){
visited[here] = 1;
cnt++;
for(int there : adj[here]){
if(visited[there]) continue;
dfs(there);
}
return;
}
int main(){
cin >> n;
cin >> m;
for(int i=0; i<m; i++){
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1);
cout << cnt-1;
return 0;
}
'자료구조 & 알고리즘' 카테고리의 다른 글
[C++] 백준 1012 유기농 배추 (0) | 2023.07.31 |
---|---|
[C++] 백준 2178 미로탐색 (0) | 2023.07.30 |
힙(Heap), 힙화(Heapify), 최댓값, 최솟값 구하기, 구현 (0) | 2023.02.25 |
이진탐색트리 노드 삭제 개념, 구현 (0) | 2023.02.24 |
이진탐색트리 최댓값, 최솟값 노드 찾기, 구현 (0) | 2023.02.23 |
댓글