BFS 방식을 이용
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int num, pairs, counts;
bool visited[101];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> num >> pairs;
int from, to;
vector<vector<int>> graph(num + 1);
for (int i = 0; i < pairs; i++)
{
cin >> from >> to;
graph[from].push_back(to);
graph[to].push_back(from);
}
queue<int> q;
q.push(1);
visited[1] = true;
while (!q.empty())
{
int f = q.front();
q.pop();
for (int i = 0; i < graph[f].size(); i++)
if (!visited[graph[f][i]])
{
visited[graph[f][i]] = true;
q.push(graph[f][i]);
counts++;
}
}
cout << counts;
return 0;
}