#include <bits/stdc++.h>
using namespace std;

// Function to add an edge to the adjacency list
void addEdge(vector<int> adj[], int u, int v) {
    adj[u].push_back(v); // Add v to u's list
    adj[v].push_back(u); // Add u to v's list (for undirected graph)
}

// Function to perform BFS
void BFS(vector<int> adj[], int V, int start) {
    vector<bool> visited(V, false); // To keep track of visited nodes
    queue<int> q; // Queue for BFS

    // Start BFS from the given starting node
    visited[start] = true;
    q.push(start);

    cout << "BFS traversal starting from node " << start << ": ";
    while (!q.empty()) {
        int node = q.front();
        q.pop();
        cout << node << " ";

        // Visit all unvisited neighbors of the current node
        for (int neighbor : adj[node]) {
            if (!visited[neighbor]) {
                visited[neighbor] = true;
                q.push(neighbor);
            }
        }
    }
    cout << endl;
}

int main() {
    int V = 12; // Number of vertices
    vector<int> adj[V]; // Adjacency list

    // Adding edges
    addEdge(adj, 0, 1);
    addEdge(adj, 0, 2);
    addEdge(adj, 0, 4);
    addEdge(adj, 1, 4);
 
    addEdge(adj, 2, 4);
    addEdge(adj, 2, 9);
    addEdge(adj, 2, 5);
    addEdge(adj, 2, 10);
    addEdge(adj, 9, 11);
    addEdge(adj, 10, 11);
    addEdge(adj, 5, 6);
    addEdge(adj, 5, 7);
    addEdge(adj, 5, 8);
    addEdge(adj, 7, 8);

    // Perform BFS starting from node 0
    BFS(adj, V, 0);

    return 0;
}
