[INST] Write BFS in c++./n [/INST]  ###Response: Here is an example implementation of BFS in C++ using an adjacency list to represent the graph:

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

using namespace std;

void bfs(vector<vector<int>>& graph, int start) {
    int n = graph.size();
    vector<bool> visited(n, false);
    queue<int> q;
    q.push(start);
    visited[start] = true;

    while (!q.empty()) {
        int node = q.front();
        q.pop();

        // Do something with the node (e.g. print)
        cout << node << " ";

        for (int neighbor : graph[node]) {
            if (!visited[neighbor]) {
                q.push(neighbor);
                visited[neighbor] = true;
            }
        }
    }
}

int main() {
    int n, m; // n = number of nodes, m = number of edges
    cin >> n >> m;

    // Build the graph
    vector<vector<int>> graph(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        // Add edge from a to b
        graph[a].push_back(b);
        // Add edge from b to a if undirected
        // graph[b].push_back(a);
    }

    // Perform BFS starting from node 0
    bfs(graph, 0);
    
    return 0;
}
``` 

This implementation takes in `n` (number of nodes) and `m` (number of edges) as user input, builds an adjacency list representation of the graph, and performs a BFS starting from node 0. During the BFS, the nodes are printed in the order they are visited.