#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
    int com, link;
    cin >> com >> link;

    int cnt = 0;
    queue<int> queueue;
    vector<int> graph[101];
    bool visited[101] = {false};

    for (int i = 0; i < link; i++) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    queueue.push(1);
    visited[1] = true;

    while (!queueue.empty()) {
        int cur = queueue.front();
        queueue.pop();

        for (int i = 0; i < graph[cur].size(); i++) {
            int next = graph[cur][i];
            if (!visited[next]) {
                visited[next] = true;
                queueue.push(next);
            }
        }
    }
    
    for (int i = 2; i <= com; i++) {
        if (visited[i]) cnt++;
    }

    cout << cnt;
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: