title: What do I need to do to display the shortest path using this BFS code?
body: <p>I've written a C++ program to find out the shortest path using BFS algorithm. However, I can't find a way to print out the path, as in, the nodes which make the shortest path. What should I add so that it's possible for me to print out that path? </p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;bits/stdc++.h&gt;
  using namespace std;
  using ll = long long;
  using st = set&lt;ll&gt;;
  using kiwi = queue&lt;ll&gt;;
  #define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  const ll mx=1e5+123;
  bool visited[mx];
  ll dist[mx];
  int main(){
      fastio;
      ll node, edge;
      cin&gt;&gt;node&gt;&gt;edge;
      st adj[node+1];
      for(ll i=1;i&lt;=edge;++i){
          ll node1, node2;
          cin&gt;&gt;node1&gt;&gt;node2;
          adj[node1].emplace(node2);
          adj[node2].emplace(node1);
      }
      ///BFS
      ll src, dest; cin&gt;&gt;src&gt;&gt;dest;
      kiwi q;
      visited[src]=true; dist[src]=0;
      q.push(src);
      while(!q.empty()){
          ll s=q.front(); q.pop();
          for(auto&amp; x:adj[s]){
              if(visited[x]) continue;
              visited[x] = true;
              dist[x] = dist[s]+1;
              q.push(x);
          }
      }
      cout&lt;&lt;dist[dest]&lt;&lt;endl;
  return 0;
  }
  </code></pre>